0

Possible Duplicate:
What kind of object does @[obj1, obj2] create?

Looking at the Master-Detail Template in Xcode, in the App Delegate the SplitViewController's view controllers are set like so:

self.splitViewController.viewControllers = @[masterNavigationController, detailNavigationController];

I don't know what the purpose of the @ sign is before the square brackets. Is this just how NSArrays are made when not using [NSArray arrayWithObjects:]?

Community
  • 1
  • 1
Infinity James
  • 4,667
  • 5
  • 23
  • 36
  • `@` in general means 'what follows is an Objective-C object or symbol'; see mipaldi's answer for what it means with square brackets. Off the top of my head it also works with quotation marks (for strings), curly brackets (for dictionaries), ordinary brackets (for numbers) and the normal range of special keywords (interface, selector, class, etc). – Tommy Oct 16 '12 at 17:17
  • Yeah, I've been learning Objective-C for little over a month now, so I've seen a hell of a lot of @"NSString", @selector(method:) and [@"Format Object: %@", object] but I had never seen @[]. – Infinity James Oct 16 '12 at 17:50
  • @InfinityJames the new Objective-C literal syntax turned up only this year so that's possibly why you haven't seen it around all that much yet. Since all it really does is improve readability there's a pretty good argument for ignoring it if your code is otherwise very stable. – Tommy Oct 16 '12 at 19:27
  • Cheers Tommy, that makes sense. I was wondering if it was another iOS 6 addition. – Infinity James Oct 17 '12 at 09:35
  • It's not technically an iOS 6 addition because it's something the compiler does just to simplify the syntax rather than new functionality, but it's turned up more or less with iOS 6 so that's definitely the context in which you're most likely to see usage. – Tommy Oct 17 '12 at 20:27

1 Answers1

3

It's a new syntax feature. It's syntactic sugar for creating an array (NSArray) with the given objects.

mipadi
  • 398,885
  • 90
  • 523
  • 479