Skip to content

Instantly share code, notes, and snippets.

@jjacobson93
Created March 14, 2017 20:58
Show Gist options
  • Save jjacobson93/6d311e52eab5cf7d52a375e6e82120fd to your computer and use it in GitHub Desktop.
Save jjacobson93/6d311e52eab5cf7d52a375e6e82120fd to your computer and use it in GitHub Desktop.
Swift ?. Operator
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