Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 13, 2022 12:32 am GMT

100 Days of Swift - Day 6 (and 7)

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.


Original Link: https://dev.to/davjvo/100-days-of-swift-day-6-and-7-5ep1

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To