July 2017
Intermediate to advanced
284 pages
6h 45m
English
And in case you haven’t had enough of functions from this chapter, it’s always good to know that in Swift, you can have a function inside a function:
| | func myFunctionWithNumber(someNumber: Int) { |
| | |
| | func increment(var someNumber: Int) -> Int { |
| | return someNumber + 10 |
| | } |
| | |
| | let incrementedNumber = increment(someNumber) |
| | println("The incremented number is \(incrementedNumber)") |
| | } |
| | |
| | myFunctionWithNumber(5) |
| | // The incremented number is 15 |
| | @end |
Swift functions have a lot of options and a lot of power. As you start writing in Swift, remember: with great power comes great responsibility. Optimize for readability over cleverness!
Swift best practices haven’t been fully established yet, and the language is still constantly ...
Read now
Unlock full access