Created
December 14, 2018 07:04
-
-
Save LeeKahSeng/9b79a44216bea9d220642e8d36aa7993 to your computer and use it in GitHub Desktop.
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
let str: String? = "test" | |
// Optional binding using 'if' | |
if let value = str { | |
print(value) | |
} | |
// Optional binding using guard | |
guard let value = str else { | |
return | |
} | |
print(value) | |
// Optional chaining | |
if let value = str?.data(using: .utf8)?.first { | |
print(value) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment