Sign up for FlowVella
Sign up with FacebookAlready have an account? Sign in now
By registering you are agreeing to our
Terms of Service
Loading Flow
Manning, Jon, Paris Buttfield-Addison, and Tim Nugent. Swift Development with Cocoa. O'Reilly Media, 2014
Functions can be nested.
Functions are a
first-class type
Functions can optionally have external parameter names
Functions:
Value Capture
func createIncrementor(incrementAmount: Int) -> () -> Int {
var amount = 0
func incrementor() -> Int {
amount += incrementAmount
return amount
}
return incrementor
}
var incrementByTen = createIncrementor(10)
incrementByTen() //10
incrementByTen() //20
var incrementByFifteen = createIncrementor(15)
incrementByFifteen() //15
incrementByFifteen() //30
Due to time constraints, we decided to remove a discussion of value capture from our presentation.
But it's still interesting, so read and enjoy!