Reputation: 825
I understand that when we declare enum like the ones below, the values are default to type "int"
enum{
category0,
category1
};
However, I am getting issues now that iOS supports 64-bit. The solution I am thinking to prevent changing a lot in my code is to make this enum values default to "NSInteger" instead of "int". On my understanding, the system will decide whether NSInteger will be of type int or long depending if it's running on 32 or 64 bit. I am having difficulty understanding enum so I will appreciate your help on this. Thanks
If I use typedef as suggested by the comments:
typedef NS_ENUM(NSInteger, Category){
category0,
category1
}
how should i use it? Normally when I compare it with, say, tableview's indexpath.section, i do this
if(indexpath.section == category0){
...
}
if I declare that "Category", do I need to use it? Sorry I don't quite understand typedef.
Upvotes: 0
Views: 3451
Reputation: 17043
Try
typedef enum{
category0,
category1
} Category;
or
typedef NS_ENUM(NSInteger, Category) {
category0,
category1
};
You also can explicitly set integer numbers to your enums values
typedef NS_ENUM(NSInteger, Category) {
category0 = 0,
category1 = 1,
category42 = 42
};
Then you can use them the same as int
if(indexpath.section == category0){
...
}
Upvotes: 1