I would know how to merge two array which contain some duplicate :
Here is an exemple to illustrate what I want to do :
// Here is some dictionary which contain an unique "id" key.
NSDictionary *dico1 = [NSDictionary dictionaryWithObjectsAndKeys:
@"11111111", @"id", nil];
NSDictionary *dico2 = [NSDictionary dictionaryWithObjectsAndKeys:
@"22222222", @"id", nil];
NSDictionary *dico3 = [NSDictionary dictionaryWithObjectsAndKeys:
@"33333333", @"id", nil];
NSDictionary *dico4 = [NSDictionary dictionaryWithObjectsAndKeys:
@"44444444", @"id", nil];
NSDictionary *dico5 = [NSDictionary dictionaryWithObjectsAndKeys:
@"55555555", @"id", nil];
// And here is duplicates of the 2nd and 3td dictionary.
NSDictionary *dico2_bis = [NSDictionary dictionaryWithObjectsAndKeys:
@"22222222", @"id", nil];
NSDictionary *dico3_bis = [NSDictionary dictionaryWithObjectsAndKeys:
@"33333333", @"id", nil];
And now I have an array which contain some of those dictionaries :
NSArray *currentArray = [NSArray arrayWithObjects:
dico1, dico2, dico3, nil];
And here is the new array to be merged with the first one which contain some duplicate and new “data” :
NSArray *tempArray = [NSArray arrayWithObjects:
dico2_bis, dico3_bis, dico4, dico5, nil];
My goal, at the final stage, is to have an array which contains all dictionaries with all duplicate deleted
NSArray *finalArray = [NSArray arrayWithObjects:
dico1, dico2, dico3, dico4, dico5, nil];
I don’t know how what is the most efficient solution, the merge do have to be fast. Do I have to implement a fast enumeration or a block based enumeration algorithm, or maybe a NSPredicate implementation ?.
I’ve already search about NSPredicate but I’ve not found a way to filter an array with an other array =/
Any help would be appreciated.
You do not use NSArrays, what you need is a set which automatically eliminates “duplicates” (a “doubloon” is a Spanish gold coin). So you are using simply an NSMutableSet and add your NSDictionaries to it.