Last active
August 29, 2015 14:22
-
-
Save delba/e86acf48314f64aa7daf to your computer and use it in GitHub Desktop.
Catch conditions
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 doSomething(object: AnyObject) { | |
guard let object = object as? String where object.hasPrefix("hel") else { | |
return | |
} | |
print(object.uppercaseString) | |
} | |
doSomething("hello") | |
func doSomethingWithBool(bool: Boolean, name: String?) { | |
guard bool, let name = name else { | |
return | |
} | |
print("bool is true and name \(name)") | |
} | |
doSomethingWithBool(true, name: "damien") | |
func multiUnwrap(URL: NSURL?) { | |
guard let URL = URL, host = URL.host, path = URL.path else { | |
return | |
} | |
print(URL, host, path) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment