I have a typedef
definition in Objective-C like this:
typedef NS_ENUM(NSInteger, MyStatus) {
MyStatusUnknown = -1,
MyStatusBad = 0,
MyStatusGood = 1
}
This enum is in a pod, and it's used by several downstream pods, and the app like this:
@property (readonly, nonatomic, assign) MyStatus myStatus;
I need to convert class with typedef
to Swift without changing the signature of enum definition in downstream pods.
I tried a straight forward conversion first:
enum MyStatus: Int {
case unknown = -1
case bad
case good
}
But in this case, the property statement above will show an error:
Interface type cannot be statically allocated
This error can be resolved by changing property to
@property (readonly, nonatomic, assign) MyStatus *myStatus;
but as I said before, I cannot change this property definition.
So how to convert typedef
to Swift, while maintaining its backward compatibility with existing Objective-C property?