Using Set/Array KVC operators
Using Set/Array KVC operators
- Subject: Using Set/Array KVC operators
- From: Sam Krishna <email@hidden>
- Date: Thu, 18 Mar 2010 19:15:22 -0400
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@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