1

how can I create an enum with "." or "-" in their names? I want something like:

 enum Options: String {
     case option1, option2, option2.1, option3
 }

Using backticks (``) doesn't work. Is there some work-around I can do?

User2021
  • 31
  • 1

2 Answers2

0

Neither character can be part of an identifier name. See https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html for the grammar.

Gereon
  • 17,258
  • 4
  • 42
  • 73
0

Like Gereon says, basically, you can't. It is a very archaic system. But if you can find a good emoji you like, that'll work.

enum Option: String {
  case option1, option2, option21, option3
}

Also, note that each one is an Option, not an Options.

  • IMO it would be better to use something like option2a – Leo Dabus Dec 14 '20 at 16:38
  • I hate underscores, but I still use a lot of them because I think they’re the best substitute for periods. e.g. https://developer.apple.com/documentation/metal/mtlfeatureset –  Dec 14 '20 at 17:03