Last active
March 14, 2017 20:57
-
-
Save jjacobson93/afa89274612fd78855794b86bceb844e to your computer and use it in GitHub Desktop.
Swift Guard-let Statement
This file contains hidden or 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 giveMeAStringMaybe(_ maybe: Bool) -> String? { | |
return maybe ? "Yes!" : nil | |
} | |
let str: String? = giveMeAStringMaybe(true) | |
guard let unwrappedStr = str else { | |
print("str is nil") | |
// unwrappedStr is NOT accessible here | |
return | |
} | |
// unwrappedStr is accessible here | |
print(unwrappedStr) // prints: "Yes!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment