2

How do I declare an array of arrays in Objective-C?

1
  • If you're very new to programming, asking questions on Stack Overflow is not the place you need to be. You should find a good book or a series of online tutorials. Have a look at Good resources for learning ObjC. The Big Nerd Ranch books are excellent, and lots of people like the Stanford iOS course on iTunes U. Good luck! Commented Feb 24, 2014 at 3:28

3 Answers 3

3

For example

NSArray *arr = @[ @[ @'0', @'1', @'2'], 
                  @[ @'0', @'1', @'2']];
Sign up to request clarification or add additional context in comments.

Comments

2
NSArray *arrayOfArrays = [NSArray arrayWithObjects:
              [NSArray arrayWithObjects:@"Hello!", @"My", @"name", @"is", nil],
              [NSArray arrayWithObjects:@"1", @"2", @"3", @"4", nil], nil];

Comments

2

Assume you have the objects obj1,obj2,...,obj9

Then this would create an array containing three members:

NSArray *array = @[obj1,obj2,obj3];

And this would create an array of arrays, each containing three members:

NSArray *array = @[ @[obj1,obj2,obj3], @[obj4,obj5,obj6], @[obj7,obj8,obj9] ];

Comments