Created
November 24, 2015 10:22
-
-
Save JanGorman/482c497cd42b849f4636 to your computer and use it in GitHub Desktop.
Swift tuple unwrapping for reusable guard statements
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 foo(url: NSURL) { | |
| guard let (components, path) = urlGuard(url) as? (NSURLComponents, String) else { | |
| return | |
| } | |
| print("Components \(components) and path \(path)") | |
| } | |
| func urlGuard(url: NSURL) -> (NSURLComponents?, String?) { | |
| guard let components = NSURLComponents(URL: url, resolvingAgainstBaseURL: false), path = components.path else { | |
| return (nil, nil) | |
| } | |
| return (components, path) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment