• 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 key from the content of a set
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDictionary key from the content of a set


  • Subject: Re: NSDictionary key from the content of a set
  • From: Tim McDonald <email@hidden>
  • Date: Thu, 15 Jan 2009 18:04:03 +0000

Thanks for the response.

The code wasn't working as I expected because I'd failed to initialise the setOfValuesForCharacteristicTypes NSMutableSet which I was using check the hashFromCharacteristicTypes before sending the hash to the dictionary.

I'd presumed it was a problem with set object thinking they weren't equal. However, Cocoa's clever enough to know when two sets are really identical; i.e. :

NSSet *Set1 = [NSSet setWithObjects:O1, O2, nil];
NSSet *Set2 = [NSSet setWithObjects:O2, O1, nil];

NSLog(@"Check = %i",[Set1 isEqual:Set2]);


Prints "Check = 1" like I'd expect it to.

Best Regards

Tim

On 15 Jan 2009, at 15:14, Benjamin Stiglitz wrote:

I'm trying to create an NSDictionary that uses key based upon the contents of a NSSet (specifically a set of NSManagedObjectID's). I'm currently at a bit loss as to how to do it. My various attempts at a hash based solution (see below) don't appear to be working.

Are you creating a map from the NSSet to something else? An NSMapTable may be more appropriate.


A note on your pasted code:
NSString *hashFromCharacteristicTypes = [NSString stringWithFormat: [[NSNumber numberWithInteger:hashInt] stringValue]];

NSDictionary keys can be any object that adheres to NSCopying, so you don’t need to convert the number to a string before placing it in the dictionary.


(In fact, you can make the set the key, but I have a feeling you probably don’t want to copy the set.)


_______________________________________________

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: 
 >NSDictionary key from the content of a set (From: Tim McDonald <email@hidden>)
 >Re: NSDictionary key from the content of a set (From: Benjamin Stiglitz <email@hidden>)

  • Prev by Date: Re: NIB's owner doesn't get released because of NSArrayController
  • Next by Date: formatting toolbar-please help
  • Previous by thread: Re: NSDictionary key from the content of a set
  • Next by thread: Manipulating QC input ports with QCRenderer
  • Index(es):
    • Date
    • Thread