Home > AI > Language > Swift >

CaseIterable

Give enum the attribute of allCases

enum CompassDirection: CaseIterable {
    case north, south, east, west
}

print("There are \(CompassDirection.allCases.count) directions.")
// Prints "There are 4 directions."
let caseList = CompassDirection.allCases
                               .map({ "\($0)" })

Leave a Reply