Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Using an optional return type and returning nil to signify a failure.
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
You can’t perform that action at this time.