Reputation: 2758
I have a method that returns an NSArray:
-(NSArray *)arrayMethod {
if (x == 2) { return array1; } else { return array2; }
}
Can I do something like:
NSArray *finalArray = [NSArray arrayWithObject:[self arrayMethod]];
Thanks already.
Upvotes: 0
Views: 176
Reputation: 80603
You want to use this instead:
arrayWithArray: Creates and returns an array containing the objects in another given array.
- (id)arrayWithArray:(NSArray *)anArray
Upvotes: 0
Reputation: 31722
Use arrayWithArray
instead arrayWithObject
.
NSArray *finalArray = [NSArray arrayWithArray:[self arrayMethod]];
OR alternatively
NSArray *tempArray = [self arrayMethod];
NSArray *finalArray = [NSArray arrayWithArray:tempArray];
Upvotes: 1