Last active
May 19, 2017 03:39
-
-
Save armcknight/73f54da770d415545e38e30961a49488 to your computer and use it in GitHub Desktop.
Using an optional return type and returning nil to signify a failure.
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
class AnObject { | |
func resultOfWork() -> Any? {/* ... */} | |
} | |
func doSomeWork() -> Any? { | |
guard let result = anObjectInstance.resultOfWork() else { | |
// log and/or show error alert here? | |
return nil | |
} | |
// ... | |
return result | |
} | |
if let result = doSomeWork() { | |
// work with result | |
} else { | |
// or log and/or show error alert here? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment