奇怪的Objective-C语法 – 方括号和@符号

我在我的一个项目中使用GHSidebarNav,我碰到这个代码分配一个对象的数组。 我只是不知道它在做什么。 它只是一个数组? 这个奇怪的语法是什么? 我之前没有看到:

 NSArray *controllers = @[ @[ [[UINavigationController alloc] initWithRootViewController:[[GHRootViewController alloc] initWithTitle:@"Profile" withRevealBlock:revealBlock]] ], @[ [[UINavigationController alloc] initWithRootViewController:[[GHRootViewController alloc] initWithTitle:@"News Feed" withRevealBlock:revealBlock]], [[UINavigationController alloc] initWithRootViewController:[[GHMessagesViewController alloc] initWithTitle:@"Messages" withRevealBlock:revealBlock]], [[UINavigationController alloc] initWithRootViewController:[[GHRootViewController alloc] initWithTitle:@"Nearby" withRevealBlock:revealBlock]], [[UINavigationController alloc] initWithRootViewController:[[GHRootViewController alloc] initWithTitle:@"Events" withRevealBlock:revealBlock]], [[UINavigationController alloc] initWithRootViewController:[[GHRootViewController alloc] initWithTitle:@"Friends" withRevealBlock:revealBlock]] ] ]; 

这些是数组文字,是Xcode 4.4及更高版本中的一种容器文字。

看到:

  • 目标C编程中数组讨论中的 “文法语法”部分
  • 在LLVM站点的Objective-C文字讨论
  • WWDC 2012 现代Objective-C约19-20分钟
  • WWDC 2012 迁移到现代Objective-C

这是一个新的目标C文字是宣布一个multidimensional array。

它取代了[NSArray arrayWithObjects:[NSArray arrayWithObjects:...], [NSArray arrayWithObjects:..]]];