Using closures in swift?
Example:
let add: (Int, Int) -> Int = {
(a, b) in
return a + b
}
print(add(5, 3)) // Outputs: 8
Solution:
Closures are self-contained blocks of functionality that can be passed around and used in your code. They are similar to lambdas in other programming languages.