Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing NS_ENUM of objective-C in Swift

I have this NS_ENUM called ObserveType having two properties called Observe and ObserveAll. I can access the ObserveAll property as you can see from the picture, but I can't access Observe.

The NS_ENUM is in a header file of objective-C.

I know that changing Observe to ObserveX or ObserveXYZ will work.

But how do I access Observe without changing the name of the Observe?

Notice that I have to access the Observe on Swift.

enter image description here

like image 732
Shubhashis Avatar asked Sep 16 '25 18:09

Shubhashis


1 Answers

In addition to answers above, I'd like to point out that you can give your Objective-C NS_ENUM a Swift name with NS_SWIFT_NAME macro:

typedef NS_ENUM(NSUInteger, XYZAwesomeEnum) {
    XYZAwesomeEnumA,
    XYZAwesomeEnumB,
    XYZAwesomeEnumC,
} NS_SWIFT_NAME(AwesomeEnum);

Use it later in Swift:

AwesomeEnum.a

Apple Developer: Renaming Objective-C APIs for Swift

like image 83
FreeNickname Avatar answered Sep 18 '25 09:09

FreeNickname