Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Private Enum Declaration

In an Objective-C class I have a @private ivar that uses an enum of the form:

typedef NS_ENUM(NSInteger, PlayerStateType) {
    PlayerStateOff,
    PlayerStatePlaying,
    PlayerStatePaused
};

However, I include this definition in the header file of that class (since it's used in it). This effectively makes the type public, which isn't what I intended. How can I make this enum type private?

like image 338
Mr. Smith Avatar asked Aug 25 '26 07:08

Mr. Smith


2 Answers

Adding my comment as an answer.

You can add this in your .m class so that while importing it is not shared with other classes. You can just add it below your import statements. If the params of this type are used only in this .m class, you can declare that also in this .m file.

Your .m class will look like,

typedef NS_ENUM(NSInteger, PlayerStateType) {
    PlayerStateOff,
    PlayerStatePlaying,
    PlayerStatePaused
};

@interface ViewController () //Use an extension like this in .m class

@property (nonatomic) PlayerStateType param;

@end
like image 150
iDev Avatar answered Aug 27 '26 22:08

iDev


Define it in .m file & declare your privare ivar in controller category in .m file. To know about controller category take a look at Difference between @interface definition in .h and .m file.

like image 38
Rahul Wakade Avatar answered Aug 27 '26 21:08

Rahul Wakade



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!