I saw this piece of code in the Swift 2.1 Programming Language Guide from Apple
func makeIncrementer() -> ((Int) -> Int) {
func addOne(number: Int) -> Int {
return 1 + number
}
return addOne
}
var increment = makeIncrementer()
increment(7)
While I do understand how the scope of the inner function is available outside it's execution block - thanks to this, I can't understand how passing 7 as argument to increment() is actually taken as an argument to the inner function, when increment() actually points to the outer function.
I also want to know when makeIncrementer() is actually executed? Does it when it is assigned to increment() or when increment() gets an argument passed?