-1

I was looking at a recent post that had this snippet of code in it:

NSDictionary *attrs =
    @{ NSForegroundColorAttributeName : [UIColor grayColor],
       };
NSString *currentRank = @"Sample text";
[currentRank drawAtPoint:CGPointMake(100, 100) withAttributes:attrs];

I'm very used to strings with the @ in front of them in iOS (e.g. @"This is some constant text."). But I've never seen an @ in front of a braced structure before (Maybe I've been out of "the loop"...or was never in it ;).

Can somebody tell me what the @{ } structure means in iOS?

FuzzyBunnySlippers
  • 3,387
  • 2
  • 18
  • 28

2 Answers2

4

The @{} is a NSDictionary shorthand. It's called 'NSDictionary literal', and here's the documentation:

http://clang.llvm.org/docs/ObjectiveCLiterals.html

Fredrik E
  • 1,840
  • 13
  • 18
1

@{} is a short hand way of creating an NSDictionary.

NSDictionary *dict = [[NSDictionary alloc] init];

is equivalent to

NSDictionary *dict = @{};
Connor Pearson
  • 63,902
  • 28
  • 145
  • 142