Reputation: 161
Is there a Cocoa class has similar functionality to enumerated values from C? I know that I can just use enums in Cocoa, but what if I want to put an enum in an NSArray (which only accepts objects)?
Upvotes: 0
Views: 579
Reputation: 237100
In Cocoa, global constants are usually used in place of enums in places where the values will logically be included in a collection. For example:
NSString * const HandTool = @"HandTool__InternalValue";
NSString * const BrushTool = @"BrushTool__InternalValue";
NSString * const EraserTool = @"EraserTool__InternalValue";
For example, all the NSAttributedString keys are enum-like, but are represented in this way.
Upvotes: 5
Reputation: 225132
An enum is just an integer type - you can wrap it in NSNumber
to put it in an NSArray
.
Upvotes: 7