Skip to content

Instantly share code, notes, and snippets.

@es-kumagai
Last active October 14, 2015 08:43
Show Gist options
  • Save es-kumagai/225b008bf810a18eeb1b to your computer and use it in GitHub Desktop.
Save es-kumagai/225b008bf810a18eeb1b to your computer and use it in GitHub Desktop.
暗黙アンラップな列挙型の値を switch にかけるとき。 Ref: https://twitter.com/ktanaka117/status/654199236070764544
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")
}
}
}
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