Dumb newbie question about objects and scalars
Dumb newbie question about objects and scalars
- Subject: Dumb newbie question about objects and scalars
- From: John Brownlow <email@hidden>
- Date: Mon, 14 Mar 2005 11:07:29 -0500
This is really a dumb question but bear with me.
I have an enumerated type like this:
typedef enum
{ GLFreeform,
GLSlugline,
GLAction,
GLCharacter,
GLParenthetical,
GLDialog,
GLTransition,
GLShot
} GLBehaviorStyle;
I would like to use it as a new attribute in an attributed string so
that I can do this kind of thing:
NSDictionary *attributes = [someString attributesAtIndex:index
effectiveRange:range];
GLBehaviorStyle theBehavior = [objectForKey:
GLBehaviorStyleAttributeName];
switch ( theBehavior ) {
case GLFreeform: {...}
case GLSlugline: {...}
case GLAction: {...}
etcetera
However this doesn't work because the 'objectForKey' is supposed to be
an object, not a scalar value, which is what an enum is at heart.
So I could handle this by making GLAction and all the rest NSNumbers I
suppose:
NSNumber *GLFreeform = [NSNumber numberWithUnsignedInt: 0];
NSNumber *GLSlugline = [NSNumber numberWithUnsignedInt: 1];
NSNumber *GLAction = [NSNumber numberWithUnsignedInt: 2];
and amend the switch accordingly but then it is a lot less readable:
switch ( [theBehavior intValue] )
case [GLFreeform intValue]: {...}
case [GLSlugline intValue]: {...}
case [GLAction intValue]: {...}
Ugh.
So what's the best solution for representing scalars in Objective-C
datastructures that want to hold pointers to objects?? There has to be
some neat way of doing it that I'm missing.
--
John Brownlow
Deep Fried Films, Inc
http://www.johnbrownlow.com
http://www.pinkheadedbug.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden