Skip to content

Instantly share code, notes, and snippets.

@GrfxGuru
Created March 11, 2017 05:41
Show Gist options
  • Save GrfxGuru/1b1b64c6e2c8a4ef1a156103c80161fb to your computer and use it in GitHub Desktop.
Save GrfxGuru/1b1b64c6e2c8a4ef1a156103c80161fb to your computer and use it in GitHub Desktop.
Example of using Guard to exit early with readable code
func nameOnTheList(name: String) {
guard name == "Peter" else {
print("Not getting in!")
return
}
print("Come on in!")
}
nameOnTheList(name: "Peter")
nameOnTheList(name: "Ken")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment