2

Any exprerience on this I have for example the following enum written in objc

typedef enum {
  Type1,
  Type2
} Type;

extension Type: RawRepresentable {
    typealias RawValue = UInt32
}

compiler crashes when I'm trying to conform to RawRepresentable.The only thing that I can imaging is that RawRepresentable works only with swift enums.

Any ideas?

sger
  • 719
  • 2
  • 12
  • 26

1 Answers1

4

Forget about using raw C enum and use the Objective-C NS_ENUM macro:

typedef NS_ENUM(NSInteger, MyEnumType) {
    Type1,
    Type2
};

Then in Swift the enum will be already RawRepresentable. You cannot add that conformance this way. Well, you probably could, but you will have to also declare init?(rawValue:) and var rawValue.

Sulthan
  • 128,090
  • 22
  • 218
  • 270