Moshe Moshe - 1 year ago 84
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];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download