Reputation: 157
I've seen this in the book I'm reading but I don't know what it means and what it does. Is it something like a function? I've tried looking at the Swift language book by Apple but could not find the answer.
Thanks
Upvotes: 0
Views: 128
Reputation: 3412
This syntax is mostly used for declaring closure
in Swift.
e.g.
let something = { print("something") }
something()//prints 'something"
Here we are declaring closure named something
and then calling it later.
We can declare closures with parameters also as:
let something = { (str: String) in
print("something param: \(str)")
}
something("ok")//prints "something param: ok"
We can even declare closures with return value as:
let something = { (str: String) -> Bool in
print("something param: \(str)")
return true
}
let success = something("ok")//prints "something param: ok" and return true
Upvotes: 3
Reputation: 854
Maybe you should do the swift basics first. If you want to learn more about closures you can have a look at the following side:
Upvotes: 2