Reputation: 144
How can I add an array value to another array?
I get the array using:
NSMutableArray *pointsArray = [[result componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] retain];
I want to add the first and the last value of pointsArray
to another array.
Upvotes: 0
Views: 431
Reputation: 307
This can be achieved by using this:
NSMutableArray *recentPhotos = [[NSMutableArray alloc] init];
//add one object to the array
[recentPhotos addObject: selectPhotos];
Upvotes: 0
Reputation: 22726
as follows
NSUInteger totObjects = [pointsArray count];
[yourOtherArray addObject:[pointsArray objectAtIndex:0]]; //First Object
[yourOtherArray addObject:[pointsArray objectAtIndex:totObjects-1]]; //Last Object
Upvotes: 0
Reputation: 3637
[array addObject:[pointsArray objectAtIndex:0]]; //First Object
[array addObject:[pointsArray lastObject]]; //Last Object
But this array
should be an NSMutableArray
.
Upvotes: 2
Reputation: 16543
Its simple just add like this
NSArray *otherArray = [[NSArray alloc] initWithObjects: [pointsArray objectAtIndex:0], [pointsArray objectAtIndex:[pointsArray count]-1],nil];
Upvotes: 0
Reputation: 31722
Get the value of array using objectAtIndex:
method of NSArray
.
Upvotes: 1