• 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: structs in Mutable containers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: structs in Mutable containers


  • Subject: Re: structs in Mutable containers
  • From: Graham Cox <email@hidden>
  • Date: Tue, 16 Sep 2008 20:24:18 +1000


On 16 Sep 2008, at 7:18 pm, Christian Giordano wrote:

... forKey:[[NSNumber alloc] initWithInt:BAND_RED]];

Not a really elegant solution but I can understand that those
containers require pointers.

Now I need to create a NSMutableArray of CGPoint, how can I make it
became a pointer?

... addObject:CGPointMake(x,y)];

returns indeed "error: incopatible type for argument 1 of 'addObject:'

Is there a more elegant way to use structs as key or as mutable
container's items?


[NSValue valueWithPoint:NSMakePoint( x, y )];

this wraps a NSPoint with an object that can be stored in a dictionary. CGPoints and NSPoints have the same structure so you can cast one to t'other.

For keys, the usual approach if your keys are simply constants is to define them as literal strings:

// .h

extern NSString* BAND_RED;


// .m

NSString* BAND_RED = @"BAND_RED";

A literal string is directly usable as an object. If the key needs to change dynamically (rare) then strings are still a good bet, but the "wrap in a NSValue" approach is acceptable I guess.


hth,

Graham
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: structs in Mutable containers
      • From: "Sean McBride" <email@hidden>
    • Re: structs in Mutable containers
      • From: "Christian Giordano" <email@hidden>
References: 
 >structs in Mutable containers (From: "Christian Giordano" <email@hidden>)

  • Prev by Date: Re: Outlet from Different Implementation?
  • Next by Date: Re: structs in Mutable containers
  • Previous by thread: Re: structs in Mutable containers
  • Next by thread: Re: structs in Mutable containers
  • Index(es):
    • Date
    • Thread