I want to use 720p, 1080p as enums in swift. However, I can't. I got an error saying "Expected a digit after integer literal prefix"
enum ASResolution {
case lowResolution
case 720p
case 1080p
caee highResolution
}
What should I do?
I revised my code as below:
enum ASResolution:Int {
case low = 1
case HD = 720
case fullHD = 1080
case high = 2000
}
There isn't much you can do if you want to keep those names. An enum case is an identifier, and as you can see from the Language Reference there are restrictions for what you can use as the first character.
So, pretty much as you can't start a variable name with a digit (they are identifiers as well), you can't start an enum case with a digit.
The few options you have are:
sevenTwoZeroP and oneZeroEightZeroP) or synonyms (HDReady and FullHD)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With