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:
Asked
Active
Viewed 2,001 times
4

Sateesh Yemireddi
- 4,289
- 1
- 20
- 37

Sarvesh
- 77
- 8
-
3Please post the code as snippet, not as screenshot. – Ahmad F Nov 12 '18 at 12:32
-
3Related? https://stackoverflow.com/questions/342152/why-cant-variable-names-start-with-numbers – J. Doe Nov 12 '18 at 12:36
-
@J.Doe seems to be the same issue – Sarvesh Nov 12 '18 at 12:40
2 Answers
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
-
3It'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