Skip to content

Instantly share code, notes, and snippets.

@konrad1977
Created June 13, 2015 12:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save konrad1977/efb4469d56a0f01af134 to your computer and use it in GitHub Desktop.
Save konrad1977/efb4469d56a0f01af134 to your computer and use it in GitHub Desktop.
swift new enums
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