Reputation: 15752
I have an enum that I use privately just for one class. Should the enum still be defined in the .h file or is there a way to include it in the .m file?
Upvotes: 1
Views: 95
Reputation: 4679
I agree with the above, make everything as local as possible. But an example where I use public enum often is when I want to initialise a class with custom init method which uses some type as a parameter. This is an example from my own code.
typedef NS_ENUM(NSUInteger, PopUpMenuType) {
PopUpMenuTypeRegular,
PopUpMenuTypeFancy
};
@interface BMPopUpMenuView : UIView
- (id)initWithFrame:(CGRect)frame menuType:(PopUpMenuType)type;
@end
Upvotes: 0
Reputation: 727047
If an enum
(or any other definition for that matter) is for private use within the implementation of a single class, then it should be defined in the .m
file with the implementation of that class. Putting it in the header would cause unnecessary recompiles of unrelated files that depend on your class, but do not care about the private enum
that it uses.
Upvotes: 2