Swift: enum names with special characters (like .) in them

1k Views Asked by At

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?

2

There are 2 best solutions below

2
On

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.

0
On

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