// *** before: ***
enum DirectionOld {
case north, south, east, west
// the list was kept by hand, and a new case was forgotten in it
static let all: [DirectionOld] = [.north, .south, .east, .west]
}
// *** in version 4.2: ***
enum Direction: CaseIterable {
case north, south, east, west
}
print(Direction.allCases.count) // 4
for direction in Direction.allCases {
print(direction)
}
let random = Direction.allCases.randomElement()
// the compiler builds allCases only for an enum without associated values;
// cases hidden behind @available are left out of it