This file contains 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
//: Playground - noun: a place where people can play | |
protocol ObjectMapper { | |
associatedtype SourceType | |
associatedtype ResultType | |
func map(_ object: SourceType) -> ResultType |
This file contains 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 Point: Hashable { | |
let x: Float | |
let y: Float | |
} | |
let p1 = Point(x: 0.0, y: 0.0) | |
let p2 = Point(x: 1.0, y: 1.0) | |
p1 == p2 // false |
This file contains 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 Department { } | |
protocol Employee { | |
// warning: 'weak' should not be applied to a property declaration in a protocol | |
// and will be disallowed in future versions | |
weak var department: Department? { get } | |
} |
This file contains 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
// Declared inside framework | |
struct Point: Hashable { | |
let x: Float | |
let y: Float | |
init(x: Float, y: Float) { | |
self.x = x | |
self.y = y | |
} | |
} |
This file contains 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
#if canImport(UIKit) | |
// UIKit is available! | |
import UIKit | |
#endif |
This file contains 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
// Swift 4.1 | |
#if targetEnvironment(simulator) | |
// Simulator! | |
#endif | |
// Swift 4.0 | |
#if (arch(i386) || arch(x86_64)) && os(iOS) | |
// Simulator! | |
#else | |
// Device! |
This file contains 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 friends = ["Ross", nil, "Joey", "Chandler"] | |
// Swift 4.0 | |
let array1 = friends.flatMap { $0 } // ["Ross", "Joey", "Chandler"] | |
// Swift 4.1 | |
let array2 = friends.compactMap { $0 } // ["Ross", "Joey", "Chandler"] |
This file contains 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 string = "Hello, World!" | |
let keyPath = \String.[string.startIndex] | |
string[keyPath: keyPath] |
This file contains 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 Person: Codable { | |
let firstName: String | |
let lastName: String | |
} | |
let jsonData = """ | |
{ | |
"first_name": "John", | |
"last_name": "Watson" | |
} |
This file contains 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: Equatable where Element: Equatable { | |
static func ==(lhs: Array<Element>, rhs: Array<Element>) -> Bool { | |
// do stuff | |
} | |
} |
OlderNewer