Created
          March 11, 2017 05:41 
        
      - 
      
 - 
        
Save GrfxGuru/1b1b64c6e2c8a4ef1a156103c80161fb to your computer and use it in GitHub Desktop.  
    Example of using Guard to exit early with readable code
  
        
  
    
      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
    
  
  
    
  | 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