Created
June 13, 2015 12:06
-
-
Save konrad1977/efb4469d56a0f01af134 to your computer and use it in GitHub Desktop.
swift new enums
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
enum TextCase { | |
case Uppercase(String) | |
case Lowercase(String) | |
} | |
let values: [TextCase] = [ | |
.Uppercase("FOO"), | |
.Lowercase("iamlow"), | |
.Uppercase("BAR"), | |
] | |
//Print all of some case | |
for case let .Uppercase(value) in values { | |
print(value) | |
} | |
let number:Int? = 30 | |
if case .Some(let value) = number where value > 20 { | |
print(value) | |
} | |
//Print all unwrapped values | |
let optionals: [Int?] = [nil, 10, 20, 30, nil, 40] | |
for case let number? in optionals { | |
print(number) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment