Last active
October 14, 2015 08:43
-
-
Save es-kumagai/225b008bf810a18eeb1b to your computer and use it in GitHub Desktop.
暗黙アンラップな列挙型の値を switch にかけるとき。 Ref: https://twitter.com/ktanaka117/status/654199236070764544
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 ClientType { | |
case Main | |
case Sub | |
} | |
struct MyStruct { | |
var type:ClientType! | |
func method() { | |
// 強制アンラップしたものを switch にかける | |
switch self.type! { | |
case .Main: | |
print("Main") | |
case .Sub: | |
print("Sub") | |
} | |
} | |
} |
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 ClientType { | |
case Main | |
case Sub | |
} | |
struct MyStruct { | |
var type:ClientType! | |
func method() { | |
switch self.type { | |
case .Some(.Main): | |
print("Main") | |
case .Some(.Sub): | |
print("Sub") | |
case .None: | |
print("") | |
} | |
} | |
} | |
let value = MyStruct(type: .Main) | |
value.method() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment