How to add an Array element to an NSMutableArray which already contains another array Values?
I have three different NSMutableArray
, lets say A
,B
,and C
. I am adding the A
array to the C
and from array B
I need only one element. So i need to add that element to the C
array. Please give me an ide开发者_如何学Ca.
NSMutableArray *a;
NSMutableArray *b;
NSMutableArray *c;
//somewhere they get initialized...
[c addObject:a];
[c addObject: [b objectAtIndex:n]];
int index;
NSArray *A, *B;
NSMutableArray *C = [NSMutableArray arrayWithArray:A];
[C addObject:[B objectAtIndex:index]];
[C addObjectsFromArray:A];
id o = [B objectAtIndex:0]; // first item, or find the item you're looking for
[C addObject:o];
That should do it. This assumes you've already alloc'd and init'd or otherwise own a created NSMutableArray for all of A, B and C.
[c addObjectsFromArray:a];
[c addObject:[b objectAtindex:index];
Do it like this:
if (A.count != 0) {
for (int i=0; i<=A.count-1; i++) {
[C addObject:[A objectAtIndex:i]];
}
}
This will add all the object of array A in array C.
[C addObject:[B objectAtIndex:n]];
This insert an object of array B which pointed by index 'n' in array C.
精彩评论