Evgeniy Kleban Evgeniy Kleban - 7 days ago 4x
iOS Question

Make arrays from excluding strings

I have 2 array of strings, lets say for simplicity it will be Array 1 -

and Array 2 will be -
@[@"b",@"c", @"d"]

What i want is, to create an array from strings (yes, there will be strings, sometimes long enough, i put characters just for simplicity) that exclude strings contained in previous array. And second array, that otherwise, contain string that exist in first array and not exist in second.

So, with array i privded, it would be :
resultArray1 = @[@"d]
(exist in second array, but not in first)
resultArray2 = @[@"a"]
(exist in first array, but not in second)

How to enumerate through this arrays to get what i want to? Thanks.


Make a NSMutableArray from the array with the items you want to keep, and call removeObjectsInArray: on it:

NSMutableArray res1 = [arr1 mutableCopy];
NSMutableArray res2 = [arr2 mutableCopy];