Hi all,
I have two arrays of NSDictionaries that I'm trying to "uniquely merge" by
making sure that no two dictionaries have duplicate contents. I came up with
one solution, but I wanted to see if the community had an answer that involved
using one of the KVC array operators.
Here's the original code:
// Get the array of dictionaries
NSArray *tempArray = [currentItem objectForKey:contactKey];
// Walk it
for (NSDictionary *d in tempArray)
{
// Create the predicate and filter contacts_ based on it
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"email =
%@", [d objectForKey:emailKey]];
NSArray *filteredArray = [contacts_
filteredArrayUsingPredicate:predicate];
// If there's 0 results in the filtered array, add the current
dictionary to contacts_
if ([filteredArray count] == 0)
{
[contacts_ addObject:d];
}
}
}
What I'm specifically looking for is a way to compress the above code into a
line or two using the KVC array operators, specifically either
@distinctUnionOfArrays or @distinctUnionOfObjects to uniquely merge the two
arrays of dictionaries together. I'm trying to uniquely filter based on the
email key of the dictionaries, and it would be great to flatten alll this code
out.
Any ideas?
TIA!
Namaste Playfully,
Sam
-----
If he listens in faith,
finding no fault, a man is free
and will attain the cherished worlds
of those who act in virtue.
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]