I am attempting pass a function to another function and then have the passed function executed passing to it a variable.
Here is my code:
func showSt
Rob's answer is correct, though I'd like to share an example of a simple working callback / completion handler, you can download an example project below and experiment with the getBoolValue
's input.
func getBoolValue(number : Int, completion: (Bool)->()) {
if number > 5 {
completion(true)
} else {
completion(false)
}
}
getBoolValue(number: 2) { (result) -> () in
// do stuff with the result
print(result)
}
Important to understand:
(String)->() // takes a String returns void
()->(String) // takes void returns a String