• 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
Remove specific items from an Array - is this the best way?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Remove specific items from an Array - is this the best way?
      • From: "Kyle Sluder" <email@hidden>
  • Prev by Date: Re: Killall Finder Brings Hidden Apps To Front?
  • Next by Date: Re: Remove specific items from an Array - is this the best way?
  • Previous by thread: Re: Killall Finder Brings Hidden Apps To Front?
  • Next by thread: Re: Remove specific items from an Array - is this the best way?
  • Index(es):
    • Date
    • Thread