Skip to content

Instantly share code, notes, and snippets.

@dineshba
Last active May 19, 2018 18:08
Show Gist options
  • Select an option

  • Save dineshba/3c82b8345c67438365c3f84ddb9e890f to your computer and use it in GitHub Desktop.

Select an option

Save dineshba/3c82b8345c67438365c3f84ddb9e890f to your computer and use it in GitHub Desktop.
if let laptop = programmer.laptop { // set the value of laptop if `programmer.laptop` is not nil and
// enter into if-case or enter into `else` case.
if let laptopFan = laptop.fan { // set the value of laptopFanName if `laptop.fan` is not nil and
// enter into if-case or enter into `else` case.
print("\(laptop.name) contains \(laptopFan.name) fan")
} else {
print("\(laptop.name) contains no fan") // Note: String interpolation "\(value)"
}
} else {
print("\(programmer.name) have no laptop")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment