Swift 5.x 遍历enum的case

2020-06-30  本文已影响0人  ShenYj

e.g.

enum CompassPoint: CaseIterable {
    case north
    case south
    case east
    case west
}

let numberOfDirections = CompassPoint.allCases.count
print("\(numberOfDirections) directions")

for direction in CompassPoint.allCases {
    print("direction: \(direction)")
}

输出结果:

4 directions
direction: north
direction: south
direction: east
direction: west
上一篇 下一篇

猜你喜欢

热点阅读