开发者

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.


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

But this array should be an NSMutableArray.


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


as follows

NSUInteger totObjects = [pointsArray count];
[yourOtherArray addObject:[pointsArray objectAtIndex:0]]; //First Object
[yourOtherArray addObject:[pointsArray objectAtIndex:totObjects-1]]; //Last Object


Its simple just add like this

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


This can be achieved by using this:

NSMutableArray *recentPhotos = [[NSMutableArray alloc] init];

//add one object to the array
[recentPhotos addObject: selectPhotos];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜