具有现代语法的可变数组的可变数组

Mutable array of mutable arrays with modern syntax

如何编写以下代码:

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

使用现代语法?

我会自己回答:对于 NSMutableArray 没有文字语法,所以你必须写:

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

如果您希望使用比您自己的答案更少的括号,您可以使用:

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