Last active
December 12, 2016 07:54
-
-
Save rmnblm/46b9dccb5b594bc38109912724899bbe to your computer and use it in GitHub Desktop.
Swift: Optionals Part 2
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
// Declare an optional value | |
var name: String? = "Roman" | |
// Optional chaining | |
name?.characters.count | |
if name != nil { | |
// Force unwrap | |
name!.characters.count | |
} | |
// Optional binding | |
if let unwrappedName = name { | |
unwrappedName.characters.count | |
} | |
// Variable shadowing | |
if let name = name { | |
name.characters.count | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment