Skip to content

Instantly share code, notes, and snippets.

@haranicle
Created July 25, 2015 06:33
Show Gist options
  • Save haranicle/b896f4f622121ec46759 to your computer and use it in GitHub Desktop.
Save haranicle/b896f4f622121ec46759 to your computer and use it in GitHub Desktop.
PatternMatchingについて #cswift #CodePiece
if case let .OSX(version) = platform {
print(version)
}
if case let value? = optionalValue {
}
if case let (a?, b?, c?) = (optionalA, optionalB, optionalC) {
// optionalA,B,Cすべてがoptionalじゃないときだけ実行される
print(\(a)\(b)\(c))
}
let optionals:[Int?]
for case let value? in optionals where value > 0 {
// 該当した要素だけが繰り返しの対象に
// whereの中でもfunctionつかえる
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment