April 2017
Intermediate to advanced
316 pages
9h 33m
English
Functions are self-contained blocks of code that perform a specific task.
In Swift, functions are first-class citizens, meaning that they can be stored, passed, and returned. Functions can be curried and defined as higher-order functions that take other functions as their arguments.
Functions in Swift can have multiple input parameters and multiple returns using tuples. Let's look at the following example:
func greet(name: String, day: String) ->String { return "Hello \(name), today is \(day)" } greet(name: "Francois", day:"Saturday")
Functions can have variadic parameters. Consider the following example:
// Variable number of arguments in functions - Variadic Parameters func sumOf(numbers: Int...) -> (Int, Int) { var sum = ...Read now
Unlock full access