NSDictionary key from the content of a set
NSDictionary key from the content of a set
- Subject: NSDictionary key from the content of a set
- From: Tim McDonald <email@hidden>
- Date: Thu, 15 Jan 2009 11:40:31 +0000
Hi
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.
I don't suppose anyone could give me some pointers on a better way to
approach this problem; i.e. should I be subclassing the NSSet and
repointing it's isEqual: method to isEqualToSet: ?
Cheers
Tim
NSUInteger hashInt=0;
for (SDTCharacteristicType *characteristicType in characteristicTypes)
{
hashInt = hashInt ^ [[characteristicType objectID] hash];
}
NSString *hashFromCharacteristicTypes = [NSString stringWithFormat:
[[NSNumber numberWithInteger:hashInt] stringValue]];
if ([setOfValuesForCharacteristicTypes
containsObject:hashFromCharacteristicTypes])
{
return [dictionaryOfValuesForCharacteristicTypes
objectForKey:hashFromCharacteristicTypes];
}
else
{
// this section does the actual work of finding the values to return
....
code to
....
[dictionaryOfValuesForCharacteristicTypes setObject:valuesToReturn
forKey:hashFromCharacteristicTypes ];
[setOfValuesForCharacteristicTypes
addObject:hashFromCharacteristicTypes];
return valuesToReturn;
}
______________________________________________
Tim McDonald
Dept of Mechanical Engineering
University College London
_______________________________________________
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