• 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
Re: Dumb newbie question about objects and scalars
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dumb newbie question about objects and scalars


  • Subject: Re: Dumb newbie question about objects and scalars
  • From: "Martin" <email@hidden>
  • Date: Mon, 14 Mar 2005 15:36:37 -0800

I would leave your enum typedef intact and just box the values in NSNumbers when you need. So instead of the ugly:

>switch ( [theBehavior intValue] )
>	case [GLFreeform intValue]: {...}
>	case [GLSlugline intValue]: {...}
>	case [GLAction intValue]: {...}

You do:

    switch( [theBehavior intValue] )
        case GLCharacter: { ... }
        case GLParenthetical: { ... }

You could also make your code even prettier by adding a category to NSAttributedString that defines:

   - (GLBehaviorStyle) behaviorStyleAtIndex:(unsigned)idx effectiveRange:(NSRange*)rngPtr
   {
      NSDictionary* attrs = [self attributesAtIndex:idx effectiveRange:rngPtr];
      NSNumber* valueObj =  [attrs objectForKey:GLBehaviorStyleAttributeName];
      return (nil == valueObj) ? GLBehaviorStyle_DEFAULT : [valueObj intValue];
   }


~Martin


 _______________________________________________
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: John Stiles <email@hidden>
  • Prev by Date: Re: Building NSObject question/Help
  • Next by Date: Re: Building NSObject question/Help
  • Previous by thread: Re: Dumb newbie question about objects and scalars
  • Next by thread: Re: Dumb newbie question about objects and scalars
  • Index(es):
    • Date
    • Thread