Weird objective-c syntax - square brackets and @ sign

I use GHSidebarNav in one of my projects, and I came across this code, allocating an array of objects. I just have no idea what he is doing. Is it just an array? What is this weird @[...] syntax? I have not seen this 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]] ] ]; 
+4
syntax ios objective-c iphone ipad
Nov 20
source share
2 answers

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

Cm:

+7
Nov 20
source share

This is a new C object letter declaring a multidimensional array.

It replaces [NSArray arrayWithObjects:[NSArray arrayWithObjects:...], [NSArray arrayWithObjects:..]]];

+3
Nov 20
source share



All Articles