u/danielt1263in r/swift • Recommends
On “Best way to understand closures”
Hmm, closures have nothing to do with recursion. Maybe this will help:
struct Example {
let add1 = { (a: Int, b: Int) in
a + b
}
func add2(_ a: Int, _ b: Int) -> Int {
a + b
}
}
In the above, `add1` and `add2` are identical in every way. You call them exactly the same way, you can pass them as arguments in exactly the same way. It's likely that the compiler even compiles them the same way.
A great tutorial is in the official Swift Programming Language book: https://docs.swift.org/swift-book/LanguageGuide/Closures.html
If you are looking for a video: [video