I am adding an NSMutableArray to another NSMutableArray, the problem is all the objects in the first array are the same (length size content, etc). I am guessing that when you add an array to an array the first array simple holds a pointer to a second, so how do I get it to hold a unique array? I am thinking I need to use arrayWithArray when adding but I can not figure out syntax.
My dictionary contains a number of Objects, each object has a load of image URLs which it then downloads.
My code thus far;
for (NSDictionary *obj in MyDictList)
{
[tempImageArray removeAllObjects];
for(NSString *tempImageURL in obj[@"images"])
{
tempImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:tempImageURL]]];
NSLog(@"Download Extra Image : %@, %i", tempImageURL, [UIImagePNGRepresentation(tempImage) length]);
[tempImageArray addObject:tempImage];
}
NSLog(@"Number of pics fo this event : %i", [tempImageArray count]);
// Add the array of images to the array
[eventImages addObject:tempImageArray];
}
The logs through this out (as you can see each image URL and size if different).
Download Extra Image : http://.....A...Correct...URL/file.jpg, 69516
Download Extra Image : http://.....A...Correct...URL/file.jpg, 63263
Number of pics fo this event : 2
Download Extra Image : http://.....A...Correct...URL/file.jpg, 69516
Download Extra Image : http://.....A...Correct...URL/file.jpg, 64545
Number of pics fo this event : 2
Download Extra Image : http://.....A...Correct...URL/file.jpg, 56541
Download Extra Image : http://.....A...Correct...URL/file.jpg, 69144
Download Extra Image : http://.....A...Correct...URL/file.jpg, 51585
Number of pics fo this event : 3
Download Extra Image : http://.....A...Correct...URL/file.jpg, 56813
Download Extra Image : http://.....A...Correct...URL/file.jpg, 33869
Number of pics fo this event : 2
When I then cycle through them I get 4 copies of the last array (i.e. just 2 pics).
Number of image in this Event at Row : 2, 0
Number of image in this Event at Row : 2, 1
Number of image in this Event at Row : 2, 2
Number of image in this Event at Row : 2, 3
EDIT Thanks for help, nudge in right direction and changed last line to read;
[eventImages addObject:[NSArray arrayWithArray:tempImageArray]];