Reputation: 3977
brand new to Swift here. Trying to figure out how to do a very simple call back block from any asynchronous function I write.
For example:
func downloadData(completion: (success: Bool) -> Void){
let success: Bool
//Some asynchronous task here
success = true
//Asynchronous task finished
//Now I want to pass this back
completion(success)
}
I want to be able to call this function and get the value of the success variable in the block. However I'm getting an error "Missing argument label success in call". Don't understand what is going on here. Why would I need to include the argument label? Any pointers on this would be greatly appreciated!
Upvotes: 1
Views: 193
Reputation: 285150
You have the choice:
Either you add the label in the call
completion(success: success)
or you omit the label in the declaration
func downloadData(completion: (Bool) -> Void){
The rule is: all declared labels must be passed.
Upvotes: 3