Skip to content

Instantly share code, notes, and snippets.

@sahara-ooga
Last active June 17, 2018 04:14
Show Gist options
  • Save sahara-ooga/9489ab0d5cfd4367dbc08dfc6b523964 to your computer and use it in GitHub Desktop.
Save sahara-ooga/9489ab0d5cfd4367dbc08dfc6b523964 to your computer and use it in GitHub Desktop.
WWDC2018キャッチアップ

CaseIterableプロトコルが登場。 allCasesプロパティで、その型の全値をSequenceで返す。 例えばenumの全区分値を列挙できるようになった。 (What` new in Swiftより)

enum Gait: CaseIterable {
    case walk
    case trot
    case canter
    case gallop
    case jog
}
for gait in Gait.allCases {
    print(gait)
}
/*
walk
trot
canter
gallop
jog
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment