Skip to content

Instantly share code, notes, and snippets.

@jpsim
Last active April 15, 2016 22:03
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 jpsim/63a84fe3695b063639dd2b81ab904eb7 to your computer and use it in GitHub Desktop.
Save jpsim/63a84fe3695b063639dd2b81ab904eb7 to your computer and use it in GitHub Desktop.
optional enum switch compiler issue
enum MyEnum {
case Case1, Case2
}
let myEnum: MyEnum? = .Case1
// Implicit optional unwrapping
// These first two case statements fail to compile:
//
// switch myEnum {
// case MyEnum.Case1: break
// case .Case2: break
// case nil: break
// }
// Explicit optional unwrapping
switch myEnum {
case .Some(MyEnum.Case1): break
case .Some(.Case2): break
case nil: break
}
// Force optional unwrapping
switch myEnum! {
case MyEnum.Case1: break
case .Case2: break
// case nil: break <- commented out because no longer relevant
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment