Hi. What does a closure or a named closure (aka a function) close?
What's the different between a closure and a computed property if both are called when declaring a variable? What are the signs one needs to use a computed property, a closure or a function (much like one know that a class has to be used if he wants things inherited or a structure if he wanst things that don't inherit and wants to values to change?
Thank you.
God bless, Proverbs 31
The term closure has a long history in this space. The name is derived from the fact that it ‘closes over’ the values in its scope. For example, in this code:
func makeAdder(value: Int) -> (Int) -> Int {
return { x in
return x + value
}
}
let f = makeAdder(value: 5)
print(f(3))
the closure returned by
makeAdder(value:)
captures
value
, so that it can use it after
makeAdder(value:)
has returned.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"