Last active
August 29, 2015 14:26
-
-
Save erica/1391e9d3e65c3dcdea4c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func doSomethingTake2(inout error: Error) -> String? { | |
let success = (arc4random_uniform(2) == 1) // flip a coin | |
if success {return "success"} // succeed | |
error = Error.Unlucky | |
return nil // fail | |
} | |
func doClient1Take2(inout error: Error) -> String? { | |
if let string = doSomethingTake2(&error) { | |
// blah blah other work | |
return string | |
} else { | |
return nil | |
} | |
} | |
func doClient2Take2(inout error: Error) -> String? { | |
if let string = doClient1Take2(&error) { | |
// blah blah other work | |
return string | |
} else { | |
return nil | |
} | |
} | |
func doConsumerTake2() { | |
var error = Error.NoError // have to add default condition here | |
if let result = doClient2Take2(&error) { | |
// use result here | |
print("String: \(result)") | |
} else { | |
print("Error in doClient2Take2: \(error)") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment