• 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: Roland King <email@hidden>
  • Date: Tue, 16 Sep 2008 20:37:35 +0800

well can you manage the lifetime of the CGPoints well enough to use valueWithPointer: which, if I read it correctly, doesn't free the pointer when it's done? Or just write your own NSObject derivation you can pass a CGPoint to, by value and have it copied, or as a pointer, but which it owns and frees later for you?


On Sep 16, 2008, at 6:46 PM, Christian Giordano wrote:

I just realized valueWithPoint is not available on the iPhone SDK and,
I can't understand why, it can't be discussed here. Both things of
course suck! :)

Thanks a lot, chr



On Tue, Sep 16, 2008 at 11:24 AM, Graham Cox <email@hidden> wrote:

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

_______________________________________________

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


References: 
 >structs in Mutable containers (From: "Christian Giordano" <email@hidden>)
 >Re: structs in Mutable containers (From: Graham Cox <email@hidden>)
 >Re: structs in Mutable containers (From: "Christian Giordano" <email@hidden>)

  • Prev by Date: Re: structs in Mutable containers
  • 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