NSMutableArray *insideArray = [[NSMutableArray alloc] init];
NSMutableArray *outsideArray = [[NSMutableArray alloc] init];
[insideArray addObject:@”Hello 1″];
[insideArray addObject:@”Hello 2″];
[outsideArray addObject:insideArray];
[insideArray removeAllObjects];
[insideArray addObject:@”Hello 3″];
[insideArray addObject:@”Hello 4″];
[outsideArray addObject:insideArray];
The current output is
array(
(
"Hello 3",
"Hello 4"
),
(
"Hello 3",
"Hello 4"
)
)
I need a way to get the output to be
array(
(
"Hello 1",
"Hello 2"
),
(
"Hello 3",
"Hello 4"
)
)
Does anyone have a solution or could see where i’ve gone wrong? Thanks
You’re using the same NSMutableArray for both sub-arrays. You need to use two different objects. Specifically, instead of
instead use
for the quickest solution.