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












1














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










share|improve this question




















  • 3




    Please post the code as snippet, not as screenshot.
    – Ahmad F
    Nov 12 at 12:32






  • 3




    Related? stackoverflow.com/questions/342152/…
    – J. Doe
    Nov 12 at 12:36










  • @J.Doe seems to be the same issue
    – Sarvesh
    Nov 12 at 12:40
















1














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










share|improve this question




















  • 3




    Please post the code as snippet, not as screenshot.
    – Ahmad F
    Nov 12 at 12:32






  • 3




    Related? stackoverflow.com/questions/342152/…
    – J. Doe
    Nov 12 at 12:36










  • @J.Doe seems to be the same issue
    – Sarvesh
    Nov 12 at 12:40














1












1








1


0





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










share|improve this question















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







ios swift enums enumeration






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 12:32









Sateesh

1,7281715




1,7281715










asked Nov 12 at 12:31









Sarvesh

277




277








  • 3




    Please post the code as snippet, not as screenshot.
    – Ahmad F
    Nov 12 at 12:32






  • 3




    Related? stackoverflow.com/questions/342152/…
    – J. Doe
    Nov 12 at 12:36










  • @J.Doe seems to be the same issue
    – Sarvesh
    Nov 12 at 12:40














  • 3




    Please post the code as snippet, not as screenshot.
    – Ahmad F
    Nov 12 at 12:32






  • 3




    Related? stackoverflow.com/questions/342152/…
    – J. Doe
    Nov 12 at 12:36










  • @J.Doe seems to be the same issue
    – Sarvesh
    Nov 12 at 12:40








3




3




Please post the code as snippet, not as screenshot.
– Ahmad F
Nov 12 at 12:32




Please post the code as snippet, not as screenshot.
– Ahmad F
Nov 12 at 12:32




3




3




Related? stackoverflow.com/questions/342152/…
– J. Doe
Nov 12 at 12:36




Related? stackoverflow.com/questions/342152/…
– J. Doe
Nov 12 at 12:36












@J.Doe seems to be the same issue
– Sarvesh
Nov 12 at 12:40




@J.Doe seems to be the same issue
– Sarvesh
Nov 12 at 12:40












1 Answer
1






active

oldest

votes


















1














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
}





share|improve this answer























  • yes, this works
    – Sarvesh
    Nov 12 at 12:41






  • 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 at 12:42






  • 1




    @Caleb updated my answer
    – Dávid Pásztor
    Nov 12 at 13:48











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262273%2fwhy-am-i-getting-is-not-a-valid-digit-in-integer-literal-error-while-naming-sw%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














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
}





share|improve this answer























  • yes, this works
    – Sarvesh
    Nov 12 at 12:41






  • 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 at 12:42






  • 1




    @Caleb updated my answer
    – Dávid Pásztor
    Nov 12 at 13:48
















1














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
}





share|improve this answer























  • yes, this works
    – Sarvesh
    Nov 12 at 12:41






  • 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 at 12:42






  • 1




    @Caleb updated my answer
    – Dávid Pásztor
    Nov 12 at 13:48














1












1








1






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
}





share|improve this answer














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
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 12 at 13:48

























answered Nov 12 at 12:37









Dávid Pásztor

20.2k72547




20.2k72547












  • yes, this works
    – Sarvesh
    Nov 12 at 12:41






  • 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 at 12:42






  • 1




    @Caleb updated my answer
    – Dávid Pásztor
    Nov 12 at 13:48


















  • yes, this works
    – Sarvesh
    Nov 12 at 12:41






  • 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 at 12:42






  • 1




    @Caleb updated my answer
    – Dávid Pásztor
    Nov 12 at 13:48
















yes, this works
– Sarvesh
Nov 12 at 12:41




yes, this works
– Sarvesh
Nov 12 at 12:41




3




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 at 12:42




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 at 12:42




1




1




@Caleb updated my answer
– Dávid Pásztor
Nov 12 at 13:48




@Caleb updated my answer
– Dávid Pásztor
Nov 12 at 13:48


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262273%2fwhy-am-i-getting-is-not-a-valid-digit-in-integer-literal-error-while-naming-sw%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine