2

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

jscs
  • 63,694
  • 13
  • 151
  • 195
  • 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](http://stackoverflow.com/q/1374660). The Big Nerd Ranch books are excellent, and lots of people like the Stanford iOS course on iTunes U. Good luck! – jscs Feb 24 '14 at 03:28

3 Answers3

3

For example

NSArray *arr = @[ @[ @'0', @'1', @'2'], 
                  @[ @'0', @'1', @'2']];
lighter
  • 2,808
  • 3
  • 40
  • 59
2
NSArray *arrayOfArrays = [NSArray arrayWithObjects:
              [NSArray arrayWithObjects:@"Hello!", @"My", @"name", @"is", nil],
              [NSArray arrayWithObjects:@"1", @"2", @"3", @"4", nil], nil];
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] ];
Pétur Ingi Egilsson
  • 4,368
  • 5
  • 44
  • 72