March 2017
Intermediate to advanced
226 pages
5h 13m
English
In Swift, you chain methods and properties by appending period-delimited selectors. Each function in the chain returns an intermediate value, which is then passed as the receiver of the next method. This allows calls to be joined into a single statement without requiring variables that store intermediate results:
| | myInstance.surname.characters.count |
This approach creates a fluent interface.[44] This is ideally a parsimonious and more readable expression of a set of operations you want to consider as a single unit. A danger, of course, lies in overchaining. If you’re producing enormous lines of code that are difficult to debug and hard to read, if they cannot be easily commented or differentiated on updates, you’re doing something ...
Read now
Unlock full access