Created
May 1, 2016 14:28
-
-
Save thanhluu/66ffca5a8173b31b63691b17e13d55cf to your computer and use it in GitHub Desktop.
Optional Chaining
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
class Address { | |
var streetName: String? | |
var buildingNumber: String? | |
var apartmentNumber: String? | |
} | |
class Residence { | |
var address: Address? | |
} | |
class Person { | |
var residence: Residence? | |
} | |
let susan = Person() | |
let address = Address() | |
address.streetName = "1234 Something Drive" | |
address.buildingNumber = "Building 10" | |
address.apartmentNumber = "204" | |
let residence = Residence() | |
residence.address = address | |
susan.residence = residence | |
if let apartmentNumber = susan.residence?.address?.apartmentNumber { | |
print(apartmentNumber) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment