views:

69

answers:

1

I have a typedef enum I use to represent a state of a job in a queueing system and it is defined as

typedef enum  {
kTWjobStateRunning,
kTWjobStateQueued,
kTWjobStateError
}TWjobState;

Everything is fine, but now I would like to store it as an attribute in CoreData. My first idea is that an enum is basically an integer, so would wrapping the TWjobState in a NSNumber work? Do I have to use casts to persuade the compiler?

Best practice question
I saw this use of enums often in Cocoa and Foundation classes and also the use of bitmasks. Is there a more modern, more object-oriented way to achieve the same?

Thanks for your help.

+2  A: 

Storing enums in an NSNumber is the correct way to do this.

Dave DeLong
Although it will require updating if you modify the `enum` and assuming you use sequential values in the enum, you can use CoreData's validation system to set upper and lower bounds corresponding to the max/min enum values.
Barry Wark
thanks barry for the comment.
GorillaPatch