I would like remove every object from array that's value for the name key can be find in array2. I've tried it with a loop, but unfortunately my implementation doesn't worked, the if and else statement logged out every objects.
This is what I would like to achieve:
NSArray *array = @[
@{
@"type" : @"2",
@"name" : @"apple"
},
@{
@"type" : @"1",
@"name" : @"peanut"
},
@{
@"type" : @"3",
@"name" : @"orange"
},
@{
@"type" : @"1",
@"name" : @"cheese"
},
];
NSArray *array2 = @[
@{
@"type" : @"2",
@"name" : @"apple"
},
@{
@"type" : @"1",
@"name" : @"cheese"
},
@{
@"type" : @"3",
@"name" : @"orange"
},
];
// new array from array and array2, that contains the unique objects from array
NSArray *newArray = @[
@{
@"type" : @"1",
@"name" : @"peanut"
},
];
I'm not sure that it's a good approach so I would be very happy if somebody could show an example how to do it with any different technique. It doesn't matter if it has to use mutable or normal arrays, I just tried it with mutable first.
This is what we tried:
NSMutableArray *newArray = [self.array1 mutableCopy];
for (PFObject * object in newArray) {
PFObject *placeholderObject = object;
for (PFObject *object2 in self.array2) {
if ([placeholderObject[@"name"] isEqualToString:object2[@"name"]]) {
[self.array1 removeObject:object];
NSLog (@"EXISTING OBJECT FOUND %@", object);
} else {
NSLog(@"UNIQUE OBJECT FOUND %@", idO[@"hirCime"]);
}
}
}
array, therefore I can't give them a number properly,array's content is not pre-defined.subtractmethod of it, which subtracts all similar objects in A and B and results remaining unique objects.