How do I add one array into another one? The problem is that I insert this array several times in different "slots", but the array I insert changes, so I get a array with every field looking the same.
Is there an option to get the content of array 1 and put the whole content into one field of array 2?
I think the problem is that the array is somehow looking like this :
NSMutableArray *bigArray = [
0: dynamicArray
1: dynamicArray
2: dynamicArray
3: dynamicArray
]
instead of:
NSMutableArray *bigArray = [
0: contentOfDynamicArray
1: contentOfDynamicArray
2: contentOfDynamicArray
3: contentOfDynamicArray
]
My code:
twoDArray = [[NSMutableArray alloc] init];
cat1 = [[NSMutableArray alloc] init];
for (int k = 0; k < [noDuplicatesCat count]; k++) {
NSLog(@"cat1: %@", cat1);
[cat1 removeAllObjects];
for (int i = 0; i < [parseJSONArray count]; i++) {
NSMutableArray *temp;
[temp removeAllObjects];
temp = [[NSMutableArray alloc] init];
temp = [parseJSONArray objectAtIndex:i];
if ([[temp valueForKey:@"category"] isEqual:[noDuplicatesCat objectAtIndex:k]]){
NSLog(@"equal");
[cat1 addObject:temp];
} else {
NSLog(@"not equal");
}
}
[twoDArray addObject:cat1];
NSLog(@"2dArray: %@", twoDArray);
}
temp = [[NSMutableArray alloc] init];does not really create a new object, since you write a new value totempin the very next line, wiping out the new array.)cat1object intotwoDArrayagain and again.)arrayWithArraydoes create another object.