Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird objective-c syntax - square brackets and @ sign

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]]
    ]
];
like image 818
Imme22009 Avatar asked Nov 20 '12 21:11

Imme22009


1 Answers

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

See:

  • "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
like image 112
Rob Avatar answered Sep 17 '22 05:09

Rob