• 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: NSDictionary trouble
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDictionary trouble


  • Subject: Re: NSDictionary trouble
  • From: Jens Miltner <email@hidden>
  • Date: Wed, 20 Jan 2010 12:22:37 +0100


Am 20.01.2010 um 11:34 schrieb Jeremy Pereira:


On 19 Jan 2010, at 23:06, Jens Alfke wrote:


On Jan 19, 2010, at 10:46 AM, Kirk Kerekes wrote:

NSDictionary will use almost any object as a key:

From the docs:
"In general, a key can be any object (provided that it conforms to the NSCopying protocol...)"


-- and if it is an immutable object, that -copy is just a -retain.

Yes, but he said he wants to use a view as the key. Views are not immutable, and do copy themselves in response to -copy. Having a dictionary whose key objects are copies of your live views is not very useful. (Especially since the copied view will have a different hashcode from the original one, so you can't even look it up using the original view anymore...)

Well he could write a category to give him an object that satisfies all the criteria e.g (written in Mail).



@interface NSView(DictionaryKey)

-(NSNumber*) dictionaryKey;

@end

@implementation NSView(DictionaryKey)

-(NSNumber*) dictionaryKey
{
return [NSNumber numberWithUnsignedLongLong: (unsigned long long) self];
}

Slightly safer (because it does not make explicit assumptions about pointer sizes):


-(id) dictionaryKey
{
	return [NSString stringWithFormat:@"%p", self];
}


Sorry, couldn't resist ;-)

</jum>

_______________________________________________

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: NSDictionary trouble
      • From: Ken Thomases <email@hidden>
References: 
 >RE: NSDictionary trouble (From: Kirk Kerekes <email@hidden>)
 >Re: NSDictionary trouble (From: Jens Alfke <email@hidden>)
 >Re: NSDictionary trouble (From: Jeremy Pereira <email@hidden>)

  • Prev by Date: Re: NSDictionary trouble
  • Next by Date: Re: NSDictionary trouble
  • Previous by thread: Re: NSDictionary trouble
  • Next by thread: Re: NSDictionary trouble
  • Index(es):
    • Date
    • Thread