0

I am using a third party library in my Objective-C project that has an enum defined as:

typedef NS_ENUM(NSUInteger, RJBEvent)
{
    RJB_EVENT_OK = 1,
    RJB_EVENT_ERROR=2,
    RJB_EVENT_START = 4,
};

Then in Objective-C, I can do the following:

    [self.rjbLib listenForEvents:(RJB_EVENT_START|RJB_EVENT_OK|RJB_EVENT_ERROR)];

As an exercise to teach myself Swift, I'm porting the app. All's well until I run up against using this enum. There's a ton of info out there about how (or how not to) use enums in Swift, but very little to describe this bitmask-style usage. I've got this, and it compiles, but I'm not receiving the expected event notifications.

let rjbEventsMask : UInt32 = UInt32(RJBEvent.RJB_EVENT_OK.rawValue | 
    RJBEvent.RJB_EVENT_ERROR.rawValue |
    RJBEvent.RJB_EVENT_START.rawValue)

I do see a suggestion on NSHipster that I may need to change the third-party header file to use NS_OPTIONS. I'm going to try that, but changing the developer's provided .h file is a bit dangerous, so it's not my preferred approach.

Any guidance is appreciated.

Thanks! Rob

voodoobilly
  • 405
  • 7
  • 18
  • Does `rjbEventsMask` have the correct value 7 (=1+2+4) ? If you don't get notifications then the problem might be somewhere else in your code. – Martin R Dec 03 '15 at 15:38
  • Thanks for the suggestion -- yes, the value is correct. You're right, it could be somewhere else, but I'm focused on this because I can force the events to fire if I use `let rjbEventsMask = RJBEvent.RJB_EVENT_OK.rawValue` by itself. – voodoobilly Dec 03 '15 at 19:17

0 Answers0