Forward-declare enum in Objective-C

前端 未结 6 2399
陌清茗
陌清茗 2020-11-30 02:06

I\'m having trouble with enum visibility in an Objective-C program. I have two header files, and one defines a typedef enum. Another file needs to use the

6条回答
  •  伪装坚强ぢ
    2020-11-30 03:01

    What worked for a forward declaration of an enum for me in an Objective C .h file was look in the ProjectName-Swift.h file and see what it put, which happened to be the following:

    enum SwiftEnumName : NSInteger;

    I needed this forward declaration because I had a function parameter type of SwiftEnumName. And it wouldn't let me put the ProjectName-Swift.h import in the Objective C .h file.

    Then in the Objective C .m file I just had the #import "ProjectName-Swift.h" in it and just used the SwiftEnum normally.

    This was using Swift 4.1.2.

提交回复
热议问题