Objective-C - How to add objects in 2d NSMutableArrays

Posted by thary on Stack Overflow See other posts from Stack Overflow or by thary
Published on 2010-03-18T02:06:18Z Indexed on 2010/03/18 2:11 UTC
Read the original article Hit count: 448

Filed under:
|
|
|
|

Hello, I have this code

    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

© Stack Overflow or respective owner

Related posts about nsmutablearray

Related posts about 2d