Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using an enum from objective-c in swift class

I have an enum in objective-c

typedef enum {
status1,
status2,
} BattStatus;
@property (nonatomic) BattStatus batStatus;

To use it in swift, I'm doing:

switch (MySingleton.sharedInstance().batStatus){
    case status1: break
    case status2: break
    default: break
} 

It gives me error: BattStatus does not conforms to protocol 'IntervalType'. On line case status1: break

I cannot edit the first objective-c Singleton class yet. Just have to use it for now.

like image 636
CalZone Avatar asked Apr 07 '26 01:04

CalZone


1 Answers

Objective-C enum declarations are only imported as Swift enums if the NS_ENUM macro is used. You'll need to use the value property on any BattStatus instance to access its value for comparison.

You can read more here: C-Style "typedef enum" in Swift

like image 115
Nate Cook Avatar answered Apr 09 '26 17:04

Nate Cook