• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Dumb newbie question about objects and scalars
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Dumb newbie question about objects and scalars
      • From: Charilaos Skiadas <email@hidden>
  • Prev by Date: Re: Handle keyboard events
  • Next by Date: Re: Dumb newbie question about objects and scalars
  • Previous by thread: How to drag move an object?
  • Next by thread: Re: Dumb newbie question about objects and scalars
  • Index(es):
    • Date
    • Thread