Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

idelovski

macrumors regular
Original poster
Sep 11, 2008
235
0
I have a dictionary and two arrays. All three objects are mutable and first array holds all the keys from the dictionary and second array holds only a few of the keys.

So I need to remove all items from the dictionary (and the first array) except those present in the second array too. Naively the code would look something like this:

Code:
for (NSString *key in allKeys)  {
   if (![importantKeys containsObject:key])  {
      [allKeys removeObject:key];
      [theDict removeObjectForKey:key]
   }
}

The question is, how would I do it for real? Create a third array with the keys that should be removed?

EDIT:

I need to do it in response to a notification - UIApplicationDidReceiveMemoryWarningNotification, and allocating another mutable array at that point seemed as pushing my luck and inviting even more trouble, especially with multitasking.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.