2

I created a Swift enum as an Int (so it will work with Objective-c).

When I build the project, everything is fine. However, as soon as I try to import the class in a .h file (using a forward declaration @ClassName), the generated header file errors out with Redefinition of 'ClassName' as a different kind of symbol

Looking in the generated .h file I can see it generated the new type like so:

typedef SWIFT_ENUM(NSInteger, ClassName, closed) {
  type1 = 1,
  type2 = 2,
};

It underlines the ClassName saying it's been re-declared. However, it exists nowhere else in the header file (doing a search and it comes up only once) and it's only declared once in a swift file.

Any suggestions on what is going on?

RTXGamer
  • 3,215
  • 6
  • 20
  • 29
Aggressor
  • 13,323
  • 24
  • 103
  • 182

1 Answers1

2

Enums are not classes in Objective-C, so you need to use typedef instead of forward declaration in your .h file:

typedef NS_ENUM(NSInteger, ClassName);

and then in .m file, you need to import Module-Swift.h file.

timbre timbre
  • 12,648
  • 10
  • 46
  • 77