July 2017
Intermediate to advanced
284 pages
6h 45m
English
Compared to Objective-C, Swift has a lot of extra options for what type of parameters can be passed in. Here are some examples.
In Swift, there is a new concept of optional types:
Optionals say either “there is a value, and it equals x” or “there isn’t a value at all.” Optionals are similar to using nil with pointers in Objective-C, but they work for any type, not just classes. Optionals are safer and more expressive than nil pointers in Objective-C and are at the heart of many of Swift’s most powerful features.
To indicate that a parameter type is optional (can be nil), just add a question mark after the type specification:
| | func myFuncWithOptionalType(parameter: String?) { |
| | // function execution ... |
Read now
Unlock full access