Continuation of Hacking With Swift 100 Days of Swift
Day 6 (and 7) - Closures
Closures are a variable containing a function to be executed, for javascript developers this is not a new topic since they do it all the time, but for .Net developers is something almost equivalent to an action.
Writer note:
Is really interesting finding the difference between these languages
A closure in swift looks like this:
`
let myClosure = {
(name: String) in
print("This is the closure I (name) have created")
}
`
Closures can get complicated, since I see how something similar to callback hell can happen. For instance this sounds complicated to read, is complicated to do and just....
"A Closure that accepts a closure with a parameter as a parameter"
Maybe my english is wrong, but as I am still a novice to give more notes about this, I'll just drop this link which works as a base of how powerful (and fragile) working with this type of closures can be, other use case? not sure, but I have to say that implementation of a reduce method just looks so clean.
Top comments (0)