Skip to content

Instantly share code, notes, and snippets.

@LeeKahSeng
Created December 14, 2018 07:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeeKahSeng/9b79a44216bea9d220642e8d36aa7993 to your computer and use it in GitHub Desktop.
Save LeeKahSeng/9b79a44216bea9d220642e8d36aa7993 to your computer and use it in GitHub Desktop.
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