Guest User

Untitled

a guest
Oct 21st, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. func optionalTest() {
  2. let myName: String? = nil
  3. guard let name = myName
  4. else {
  5. print("I don't have a name")
  6. return //You need to return or throw an error, otherwise the compiler complains:
  7. //"error: 'guard' body may not fall through, consider using a 'return' or 'throw' to exit the scope
  8. }
  9.  
  10. print("My name is \(name)")
  11.  
  12. }
  13. optionalTest()
  14. /*
  15. I don't have a name
  16. */
Add Comment
Please, Sign In to add comment