Why am I getting 'is not a valid digit in integer literal' error while naming Swift enum case?

Viewed 1758

I'm trying to create an enum with running distances, but Swift is not letting me name the enum case with in this format 5K. I get an error saying 'K' is not a valid digit in integer literal. Here is my code: code

2 Answers

Identifiers and hence type properties/enum cases cannot start with numbers. You need to change the naming convention for your enum.

enum RaceType: String {
    case fiveK = "5K"
    case tenK = "10K"
    case marathon
}

As a cheat you could use emojis like 5 or as the starting letter.

Related