This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| public final class FirstOrAllOtherDispatcher { | |
| private var firstTimeOnlyBlock: (()->Void)? | |
| private var allOtherTimesBlock: (()->Void)? | |
| public init(firstTime: ()->Void) { | |
| self.firstTimeOnlyBlock = firstTime | |
| self.allOtherTimesBlock = nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func randBetween(range: Range<Int>) -> Int { | |
| let num = arc4random_uniform(UInt32(range.endIndex + 1)) | |
| return Int(num) + range.startIndex | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension Array { | |
| var shuffled: Array<T> { | |
| var newer = self | |
| newer.shuffle() | |
| return newer | |
| } | |
| mutating func shuffle() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import AppKit | |
| class NoMoveWindow: NSWindow { | |
| override class func standardWindowButton(b: NSWindowButton, forStyleMask m: Int) -> NSButton? { | |
| if b == NSWindowButton.DocumentVersionsButton { | |
| return nil | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension Dictionary { | |
| func map<T>(tx: Element->T) -> [T] { | |
| var memory: [T] = [] | |
| for (k, v) in self { | |
| memory.append(tx(k, v)) | |
| } | |
| return memory | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension Array { | |
| /// [1, 2, 3] by 2 produces: [1, 1, 2, 2, 3, 3] | |
| func replicated(times: UInt) -> Array { | |
| return self.reduce([], combine: { mem, curr in | |
| mem + Array(count: Int(times), repeatedValue: curr) | |
| }) | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import CoreData | |
| extension NSFetchedResultsController { | |
| var indexPaths: [NSIndexPath] { | |
| var paths = [NSIndexPath]() | |
| var sectionNumber = 0 | |
| for singleSection in sections as [NSFetchedResultsSectionInfo] { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension Array { | |
| func elementsInRange(start: Int, length: Int) -> Slice<T>? { | |
| if start >= self.count { | |
| return nil | |
| } | |
| var lastIndex = start + length | |
| if start + length > self.count { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct Dispatch { | |
| static func onMainQueue(block:()->()) { | |
| onMainQueueWithDelay(0, block: block) | |
| } | |
| static func onMainQueueWithDelay(delay: NSTimeInterval, block:()->()) { | |
| var queue: dispatch_queue_t = dispatch_get_main_queue() | |
| onQueue(queue, withDelay: delay, block: block) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Cocoa | |
| @IBDesignable | |
| class <#ClassName#> : NSView { | |
| override init(frame frameRect: NSRect) { | |
| super.init(frame: frameRect) | |
| commonSetup() | |
| } | |
NewerOlder