Reputation: 403
I want to typedef an enum that is common across several classes. I could:
1 Make the typedef in a class that the others inherit from directly
2 Typedef the enum for each of the classes.
3 Create a category for NSObject and typedef the enum there.
Whilst the first option requires no repetition -- and I think this is the best of the three -- it just feels wrong creating a whole new class just for just one enum. Is this anti-pattern? Is there a better way?
Upvotes: 3
Views: 368
Reputation: 6862
Usually done like this:
#ifndef SomeEnum_enum
#define SomeEnum_enum
typedef enum {
SomeEnumOne,
SomeEnumTwo,
SomeEnumThree
} SomeEnum;
#endif
You have to put your enum in your .h file, it can be one of a class, a separate file just for enums, a category, it really doesn't matter.
Now you can put it wherever you want, you just have to include the .h file
Upvotes: 4