3

This is a partial duplicate of Import a file in bridging-header which imports Swift header but I encounter the same issue as Rich

But what about enums declared in Swift? :(

I am porting an Obj-C iPad app to the iPhone. However I am a Swift developer who would really rather not rewrite existing functionality; replacing the UI instead.

I created a new target for the iPhone version. In my bridging header I import an obj-c class that uses #import "ProjectName-Swift.h". Since this file is autogenerated it doesn't exist when I build this new target. The linked answer is to add a @class but the legacy code makes use of an enum which is now giving the error "Expected a type".

// File that I am currently importing
-(void)setSmileyType:(SmileyFace)type andDelegate:(id<NumberRatingDelegate>)delegate;
// This line now throws an error "Expected a type"

//File that was previously auto imported
@objc public enum SmileyFace: Int {
bennyty
  • 371
  • 5
  • 18

1 Answers1

4

@objc enum in Swift is exposed as a C-enum in ProjectName-Swift.h . (Using a macro SWIFT_ENUM.)

You can put something like this into your Objective-C header files which are using the Swift enum:

typedef enum SmileyFace: NSInteger SmileyFace;

(Same as the first part of the generated code with the macro SWIFT_ENUM.)

OOPer
  • 47,149
  • 6
  • 107
  • 142
  • Thank you. My project still crashes at runtime with this change but I'm currently working under the assumption that it is unrelated. I will accept if I can get my project to start or if I find definitively that this answer is complete. – bennyty Aug 08 '17 at 13:51
  • This works for me, but why is this needed? Many other answers just say `@objc` should be enough for `Int` Swift enumerations. – Rivera Sep 02 '19 at 13:58