Reputation: 157
Given: ArrayOne = John, Bill, James, Adam
Given: ArrayTwo = Smith, Jones, Windsor, Newton
Result: ArrayThree = John Smith, Bill Jones, James Windsor, Adam Newton
Can't for the life of me figure it out. I can add ArrayTwo to the end of ArrayOne but that's not what I need.
Upvotes: 0
Views: 60
Reputation: 54600
Assuming those are NSString
s in your two arrays, just iterate through and create the combined string and add to a third array:
assert(arrayOne.count == arrayTwo.count);
NSMutableArray *result = [NSMutableArray arrayWithCapacity:arrayOne.count];
for (int i = 0; i < arrayOne.count; ++i) {
[result addObject:[NSString stringWithFormat:@"%@ %@", arrayOne[i], arrayTwo[i]]];
}
NSLog(@"%@",result);
Upvotes: 2