4

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

Sateesh Yemireddi
  • 4,289
  • 1
  • 20
  • 37
Sarvesh
  • 77
  • 8

2 Answers2

4

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
}
Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
  • 3
    It's not obvious that enum cases have anything to do with variables. Use *identifiers* to cover all those cases without implying a stronger relationship between them. – Caleb Nov 12 '18 at 12:42
0

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

Dali
  • 437
  • 1
  • 6
  • 10