奇怪的objective-c语法 - 方括号和@符号 [英] Weird objective-c syntax - square brackets and @ sign

查看:144
本文介绍了奇怪的objective-c语法 - 方括号和@符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的一个项目中使用GHSidebarNav,我遇到了这个代码,分配了一个对象数组。我只是不知道它在做什么。它只是一个阵列吗?什么是奇怪的 @ [...] 语法?我之前没见过:

I'm using GHSidebarNav in one of my projects and I came across this code allocating an array of objects. I just have no idea what its doing. Is it just an array? What is this weird @[...] syntax? I have not seen that before:

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及更高版本中的可用

These are array literals, a type of container literal, available in Xcode 4.4 and later.

参见:

  • "Literal syntax" section of the discussion of arrays in the Programming with Objective C
  • Objective-C Literals discussion at the LLVM site
  • WWDC 2012 Modern Objective-C, about 19-20 minutes into it
  • WWDC 2012 Migrating to Modern Objective-C

这篇关于奇怪的objective-c语法 - 方括号和@符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆