Search code examples
swiftobjective-cenumsuint32uint32-t

Convert to UInt32 in Swift from NS_ENUM uint32_t in Objective-C


I have this code...

Objective-c:

typedef NS_ENUM(uint32_t, EXType) {
  EXTypeBad = 0,
  EXTypeOK,
  EXTypeGood
};

EXType type = EXTypeOK;

Swift

 UInt32(type)

But I get:

initializer 'init(_:radix:)' requires that 'EXType' conform to 'StringProtocol' type: UInt32(type)

What am I doing wrong? Thanks.


Solution

  • I was able to use the rawValue property on the NSEnum. My Autocomplete didn't suggest this to me.

    UInt32(type.rawValue)