Remove specific items from an Array - is this the best way?
Remove specific items from an Array - is this the best way?
- Subject: Remove specific items from an Array - is this the best way?
- From: Steve Cronin <email@hidden>
- Date: Tue, 13 Jan 2009 02:04:15 -0600
Folks;
I have an array of 'Suspect' objects which have 'names', 'capeSize',
'hatSize', 'planetOfOrigin', all the usual stuff...
Now I also have a list of 'RebelOutposts'; a set of 'planet' name
strings,
What I want to do is remove from a usualSuspects array of Suspects any
Suspect whose 'planetOfOrigin' is in my rebelOutpost set.
Here's the wrinkle that makes my brow crinkle: I really want a
generic solution that would allow me to remove based on
'fingerprints', or ....
Here's what I'm proposing:
NSSet *workingSet = [NSSet setWithArray:usualSuspects];
NSString *searchOnKey = @"planetOfOrigin"
NSSet *removeMatchingValuesSet = [NSSet setWithSet: rebelOutpost];
offTheHook = [workingSet filteredSetUsingPredicate:[NSPredicate
predicateWithFormat:@"NOT(%K IN %@)", searchOnKey,
removeMatchingValuesSet]];
(Hopefully you can see how this lends itself to wrapping in method
with 3 parameters)
Is there a gotcha hiding in there? Nulls?
Is there a better way?
Thanks!
Steve
_______________________________________________
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