Created
March 14, 2017 20:58
-
-
Save jjacobson93/6d311e52eab5cf7d52a375e6e82120fd to your computer and use it in GitHub Desktop.
Swift ?. Operator
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 str1: String? = giveMeAStringMaybe(true) | |
let lowercaseStr1: String? = str1?.lowercased() | |
print(lowercaseStr2) // prints: "yes!" | |
let str2: String? = giveMeAStringMaybe(false) | |
let lowercaseStr2: String? = str2?.lowercased() | |
print(lowercaseStr2) // prints: nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment