G.P. Burdell
G.P. Burdell

Reputation: 161

Closest cocoa equivalent of enum

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

Answers (2)

Chuck
Chuck

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

Carl Norum
Carl Norum

Reputation: 225132

An enum is just an integer type - you can wrap it in NSNumber to put it in an NSArray.

Upvotes: 7

Related Questions