December 2014
Beginner
300 pages
8h 9m
English
Dictionaries return optionals when you try to access items. Therefore, you might want to place them into value bindings. If you don’t need the value of the key you are testing, you can instead use a regular if statement, like this:
if people[198364775] { println("Got him")} else { println("No one with that Social Security number")}
If you do in fact want the unwrapped value from the optional (if it does succeed), you can use full value binding, like this:
if let person = people[198364775] { println("Got \(person)")} else { println("No one with that social security number")}
Now you will have the unwrapped value of the optional ...
Read now
Unlock full access