This content originally appeared on DEV Community and was authored by Davmi Jose Valdez Ogando
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.
This content originally appeared on DEV Community and was authored by Davmi Jose Valdez Ogando
Davmi Jose Valdez Ogando | Sciencx (2022-04-13T00:32:23+00:00) 100 Days of Swift – Day 6 (and 7). Retrieved from https://www.scien.cx/2022/04/13/100-days-of-swift-day-6-and-7/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.