Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func optionalTest() {
- let myName: String? = nil
- guard let name = myName
- else {
- print("I don't have a name")
- return //You need to return or throw an error, otherwise the compiler complains:
- //"error: 'guard' body may not fall through, consider using a 'return' or 'throw' to exit the scope
- }
- print("My name is \(name)")
- }
- optionalTest()
- /*
- I don't have a name
- */
Add Comment
Please, Sign In to add comment