Search code examples
objective-cnsarray

Mutable array of mutable arrays with modern syntax


How can I write the following code:

self.box = [[NSMutableArray alloc] initWithObjects:
                    [NSMutableArray arrayWithObjects:_imageView1,_imageView2,_imageView3,nil],
                    [NSMutableArray arrayWithObjects:_imageView4,_imageView5,_imageView6,nil],
                    [NSMutableArray arrayWithObjects:_imageView7,_imageView8,_imageView9,nil],
                    nil];

with the modern syntax?


Solution

  • I will self answer: for NSMutableArray there is no literal syntax, so you have to write:

      self.box = [@[
        [@[ _imageView1, _imageView2, _imageView3 ] mutableCopy],
         [@[ _imageView4, _imageView5, _imageView6 ] mutableCopy],
         [@[ _imageView7, _imageView8, _imageView9 ] mutableCopy]
        ] mutableCopy];