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 decompose: (head: Element, tail: [Element])? { | |
| return count > 0 ? (self[0], Array(self[1..<count])) : nil | |
| } | |
| } | |
| extension Array { | |
| func interleave(x: Element) -> [[Element]] { | |
| guard let (head, tail) = decompose else { return [[x]] } | |
| let start = [x] + self |
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 | |
| extension Array where Element : IntegerType { | |
| var sum: Element { | |
| return reduce(0, combine: +) | |
| } | |
| var odds: [Element] { | |
| return filter { $0 % 2 != 0 } | |
| } |
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
| // Note: This must be used in an Xcode project that contains a bridging header | |
| // that includes <asl.h> | |
| import Foundation | |
| /// Provides high-level methods to access the raw data in | |
| /// an ASL message. | |
| struct SystemLogEntry { | |
| /// Key-value pairs read from ASL message | |
| let data: [String : String] |
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
| public struct CountedSet<Element : Hashable> : Hashable, CollectionType, ArrayLiteralConvertible { | |
| public typealias Index = SetIndex<Element> | |
| public typealias Generator = SetGenerator<Element> | |
| private var backingSet = Set<Element>() | |
| private var countMapping = [Int: UInt]() | |
| private var debugCountMapping: [Element : UInt] { | |
| var result = [Element : UInt]() | |
| backingSet.forEach { element in |
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 | |
| struct Change<T>: CustomDebugStringConvertible { | |
| let oldValue, newValue: T? | |
| var debugDescription: String { | |
| let prettyString: T? -> String = { return $0 != nil ? "\($0!)" : ".None" } | |
| return "ChangeType:\n\tOld value: \(prettyString(oldValue))\n\tNew value: \(prettyString(newValue))" | |
| } | |
| } |
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 UIKit | |
| /// Object observing keyboard changes and passing a `KeyboardChangeInfo` to notify about changes. | |
| final class KeyboardObserver: NSObject { | |
| typealias KeyboardChangeClosure = (KeyboardChangeInfo) -> Void | |
| let changeClosure: KeyboardChangeClosure | |
| // MARK: - Private |
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 Equatable { | |
| func oneOf(other: Self...) -> Bool { | |
| return other.contains(self) | |
| } | |
| } |
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
| public extension UIView { | |
| static var debugColors: [UIColor] { | |
| return [ | |
| .red, | |
| .green, | |
| .blue, | |
| .cyan, | |
| .yellow, | |
| .magenta, |
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 | |
| // Defining this breaks the behaviour of the existing '||' operator in some cases | |
| public func ||(lhs: NSPredicate, rhs: NSPredicate) -> NSPredicate { | |
| return NSCompoundPredicate(orPredicateWithSubpredicates: [lhs, rhs]) | |
| } | |
| func foo() { | |
| let cards = [String: [String]]() | |
| let startingContactIndex: UInt = 3 |
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 Car { | |
| let made: String | |
| } | |
| func compareDumps(lhs: Any, rhs: Any) -> Bool { | |
| var (lhsDump, rhsDump) = (String(), String()) | |
| dump(lhs, to: &lhsDump) | |
| dump(rhs, to: &rhsDump) | |
| return lhsDump == rhsDump | |
| } |