Moshe Moshe - 1 year ago 63
Objective-C Question

How would I combine two arrays in Objective-C?

What is the Objective-C equivalent of the JavaScript


Assuming that both objects are arrays, how would you combine them?

Answer Source

NSArray's arrayByAddingObjectsFromArray: is more-or-less equivalent to Javascript's .concat() method:

NSArray *newArray=[firstArray arrayByAddingObjectsFromArray:secondArray];

If you want to strip-out duplicates:

NSArray *uniqueEntries = [[NSSet setWithArray:newArray] allObjects];