Functions
Functions in Swift are more flexible than those of many other languages that you may have used. They'll certainly do most, if not all, the things you would expect when coming from C, Objective C or Java, but they also do more, in that they are also objects, just like any other types.
Function declarations offer considerable flexibility, much more so than Objective C, if you are coming from that background.
Arguments
Swift has some method parameter features not available in some languages, such as default and variadic arguments, and it is these that we will investigate first.
Note
Arguments or parameters? Both terms get used, as do argument list
and parameter list
, in both Apple's documentation and other documentation. For the purposes of this book, they are interchangeable.
Default arguments
Function parameters maybe given default values, in the following form:
func paintFace(color: String = "white") { print("I have painted my face \(color)") }
It's probably clear already that the...