Moshe Moshe - 5 months ago 14
Objective-C Question

How would I combine two arrays in Objective-C?

What is the Objective-C equivalent of the JavaScript

concat()
function?

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

Answer

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];
Comments