How to reference Swift enum in Objective-C Header

What you want to do is called forward declaration. To forward declare an enum you can do:

enum name;

But since the compiler won't know the size of the enum, you will only be able to use it as a pointer in your header file. Even doing this might prove problematic if you use compiler flags like -pedantic.

So in short, there is no good way to do this. Your best bet is not to, and access the enum from your implementation (.m) file instead.

In your implementation file, #import your swift bridging header file, and, without knowing more details about your problem, you could add private properties that use your enum like this:

@interface MyObjCClassDefinedInTheHFile()
    @property (nonatomic, assign) SomeSwiftEnum type;
@end

Hope this helps.


In Mixed OBJC - Swift projects the best way to have enums work in both types of classes will be to define the enum in an OBJC header and not in a swift class. swift enums can't be used in OBJC header files taken from the answer here


enums are one part of the swift Objective-C communication that does not always work. The thing is that in Objective-C, the enums can just be primitive types(NSInteger for example).

In swift you can have enums on more types, for example like String. Which is one of the awesome things about swift.

However, these enums wont be compiled to Objective-C because there is no equivalent for them. So they will simply be ignore and not generated in this header file that xcode creates for all your swift files. This is called Objective-C generated interface header: enter image description here

This generated file contains all the classes and enums available in objective-c . You have to mark everything you want to expose in Objective-c with @objc or make them public. You dont need any forward declaration for them to work, if you have this.

Hope this helps you figure out why your enum is not visible in Objc. Let me know if it worked out.


typedef SWIFT_ENUM(NSInteger, MyEnum);