Created
June 10, 2015 11:26
-
-
Save delba/877c5ccd3f1b6b558e4e to your computer and use it in GitHub Desktop.
switch tupple
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
typealias Result = (value: String?, error: String?) | |
let result = Result("value", nil) | |
switch result { | |
case let (.Some(value), .None): | |
print(value) | |
case let (.None, .Some(error)): | |
print(error) | |
case let (.Some(value), .None(error)): | |
print(value, error) | |
case let (.None, .None): | |
break | |
} | |
switch result { | |
case let (.Some(value), _): | |
print(value) | |
case let (_, .Some(error)): | |
print(error) | |
default: | |
break | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment