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:
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.
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.