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
| postfix operator ~~~ | |
| struct Engine { | |
| var tank: Float | |
| var consumption: Float | |
| var distance: Float | |
| var consumptionTarget: Float? | |
| static prefix func ~ (engine: Engine) -> Engine { | |
| return Engine(tank: engine.tank, |
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
| enum TaskType: String, Codable { | |
| case unknown | |
| case activity | |
| } | |
| // MARK: - APIObjectMapping | |
| extension TaskType: APIObjectMapping { | |
| typealias Object = String | |
| static func with(object: String?) -> TaskType? { |
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
| protocol APIObjectMapping { | |
| associatedtype Object | |
| static func with(object: Object?) -> Self? | |
| } | |
| protocol ClientObjectMapping { | |
| associatedtype Object | |
| var object: Object? { get } | |
| } |
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
| protocol ReusableViewType: class { | |
| static var defaultReuseIdentifier: String { get } | |
| static var nib: UINib { get } | |
| } | |
| extension ReusableViewType where Self: UIView { | |
| static var defaultReuseIdentifier: String { | |
| return NSStringFromClass(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
| func someFunction<T: SomeClass, U: SomeProtocol>(someT: T, someU: U) { | |
| // function body goes here | |
| } |
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 Buffer { | |
| var isEmpty: Bool { | |
| return items.isEmpty | |
| } | |
| var middle: Element? { | |
| return try? get(index: items.count / 2) | |
| } | |
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 Buffer<Element> { | |
| enum BufferError: Error { | |
| case outOfBounds | |
| } | |
| private var items: [Element] = [] | |
| mutating func add(_ item: Element) { | |
| items.append(item) |
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 swapTwo(_ a: inout Int, _ b: inout Int) { | |
| (a, b) = (b, a) | |
| } | |
| var x = 4 | |
| var y = 7 | |
| swapTwo(&x, &y) | |
| // What about two string, double, etc. ??? |
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
| let mediaSet: [Media] = [Video(url: "http://[email protected]", thumb: "http://[email protected]"), | |
| Video(url: "http://[email protected]", thumb: "http://[email protected]"), | |
| Media(url: "http://[email protected]")] | |
| for media in mediaSet { | |
| // We don't sure about casting result | |
| if let video = media as? Video { | |
| print("Video: \(video)") | |
| } | |
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
| class Media { | |
| var url: String | |
| init(url: String) { | |
| self.url = url | |
| } | |
| } | |
| class Video: Media { |