Last active
May 19, 2018 18:25
-
-
Save dineshba/9e791e1e117819983b7ddc0b04c4b3c0 to your computer and use it in GitHub Desktop.
This file contains 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
func printSummary(_ programmer: Programmer) { | |
guard let laptop = programmer.laptop else { // set the value of laptop if `programmer.laptop` is not nil | |
print("\(programmer.name) have no laptop") // and will go line 6. If `programmer.laptop` is nil, it will | |
return // enter into else case and return to caller of this function. | |
} | |
guard let laptopFan = laptop.fan else { // Syntax | |
print("\(laptop.name) contains no fan") // guard let constant = expression else { | |
return // return returnValue | |
} // } | |
print("\(laptop.name) contains \(laptopFan.name) fan") | |
} | |
printSummary(programmer) //guard let should be used with some function. Because it is based on early exit. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment