Shima
Shima

Reputation: 144

Add an array value to another array

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

Answers (5)

Hariprasad.J
Hariprasad.J

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

Janak Nirmal
Janak Nirmal

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

jigneshbrahmkhatri
jigneshbrahmkhatri

Reputation: 3637

[array addObject:[pointsArray objectAtIndex:0]]; //First Object
[array addObject:[pointsArray lastObject]]; //Last Object

But this array should be an NSMutableArray.

Upvotes: 2

ipraba
ipraba

Reputation: 16543

Its simple just add like this

NSArray *otherArray = [[NSArray alloc] initWithObjects: [pointsArray objectAtIndex:0], [pointsArray objectAtIndex:[pointsArray count]-1],nil];

Upvotes: 0

Jhaliya - Praveen Sharma
Jhaliya - Praveen Sharma

Reputation: 31722

Get the value of array using objectAtIndex: method of NSArray.

Upvotes: 1

Related Questions