2

I'm translating some code from Objective-C to Swift.

typedef NS_ENUM(NSUInteger, SomeType) {
    SomeTypeZero = 0,
    SomeTypeOne = 1,
    SomeTypeMax = NSUIntegerMax
};

However UInt.max gives me a compiler error: "Raw value for enum case must be a literal."

@objc enum SomeType: UInt {
    case zero = 0
    case one = 6
    case max = UInt.max
}

So what's going on here and how can I translate it, with backwards compatibility?

I make my mark
  • 841
  • 6
  • 13

1 Answers1

0

UInt.max is a value which is defined at runtime. However to be a value of an enumeration the value needs to be defined at compile time.

I make my mark
  • 841
  • 6
  • 13