Skip to content

Instantly share code, notes, and snippets.

@amberstar amberstar/gist:7861aee759b5d363d316 Secret
Last active Jan 20, 2016

Embed
What would you like to do?
Example of a completion handler that can throw
func divide(numerator: Int, denominator: Int, completion: (() throws -> Int ) -> Void ) {
if numerator == 0 || denominator == 0 {
completion {
throw NSError(domain: "Test", code: 10, userInfo: nil)
}
} else {
completion {
return enumerator / denominator
}
}
}
divide(100, denominator: 0) {
do {
let result = try $0()
print(result)
}
catch {
print("Error")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.