Last active
April 15, 2016 22:03
-
-
Save jpsim/63a84fe3695b063639dd2b81ab904eb7 to your computer and use it in GitHub Desktop.
optional enum switch compiler issue
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
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