Last active
August 29, 2015 14:26
-
-
Save erica/1735b94285634cd72c64 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 doSomething() -> String? { | |
let success = (arc4random_uniform(2) == 1) // flip a coin | |
if success {return "success"} // succeed | |
return nil // fail | |
} | |
func doClient1() -> String? { | |
if let string = doSomething() { | |
// blah blah other work | |
return string | |
} else { | |
print("Error: doSomething failed to return value") | |
return nil | |
} | |
} | |
func doClient2() -> String? { | |
if let string = doClient1() { | |
// blah blah other work | |
return string | |
} else { | |
print("Error: doClient1 failed to return value") | |
return nil | |
} | |
} | |
func doConsumer() { | |
if let result = doClient2() { | |
// use result here | |
print("String: \(result)") | |
} else { | |
print("Error encountered when calling doClient2") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment