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 Optional<Wrapped>: ExpressibleByNilLiteral { | |
case none | |
case some(Wrapped) | |
} |
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 greeting: String? = nil // preferred | |
let greeting2: String? = .none // same thing | |
let greeting3: Optional<String> = .none // same thing |
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 doSomeStuff() { | |
// magic stuff | |
} |
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 doSomeStuff() -> Void { | |
// magic stuff | |
} |
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 doSomeStuff() {} // preferred | |
func doSomeStuff2() -> Void {} // same thing | |
func doSomeStuff3() -> () {} // same thing |
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 doSomeStuff(completion: () -> Void) { | |
// magic stuff | |
} |
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 doSomeStuff(completion: (Void) -> ()) { | |
} | |
func doSomeStuff2(completion: () -> ()) { | |
} |
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 outside() { | |
doSomeStuff { result in | |
// some closure stuff | |
} | |
doSomeStuff2 { | |
// some closure stuff | |
} | |
} |
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 dumpAndCrush() -> Never { | |
// export output to log | |
// save | |
fatalError("App went dark! Check the logs why.") | |
} | |
// fatalError declaration | |
func fatalError(_ message: @autoclosure () -> String = String(), | |
file: StaticString = #file, | |
line: UInt = #line) -> Never |
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 doSomeStuff(with numbers: [Int]) { | |
guard numbers.count > 5 else { | |
preconditionFailure("Stuff happens when there are more than five numbers!") | |
} | |
// do some stuff | |
} | |
// preconditionFailure declaration | |
func preconditionFailure(_ message: @autoclosure () -> String = String(), |
OlderNewer