Skip to content

Instantly share code, notes, and snippets.

@delba
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save delba/e86acf48314f64aa7daf to your computer and use it in GitHub Desktop.
Save delba/e86acf48314f64aa7daf to your computer and use it in GitHub Desktop.
Catch conditions
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