Type safe
Don’t need to check hundred times, don’t need NSParameterAssert in most cases.
Generics
Enum
There is another a very popular use case about check result, here is a example in Alamofire/Result.swift
Default Prameter Values
Function definition will be much more graceful.
Functions with Multiple Return Values (Tuples)
Function Types as Parameter Types
Closure Expressions
All of the codes below do the same thing:
guard
Before:
After:
Could be better:
defer
Protocol Extensions
- WWDC 2015 - Session 408 - Protocol-Oriented
Programming in Swift
the Swift runtime calls the presentError() through static dispatch instead of through dynamic dispatch.
Some code snippets
Tips
Use Playground to test something when coding.
Summay