Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is @[] and @{} in Objective-C? [duplicate]

Possible Duplicate:
What are the details of “Objective-C Literals” mentioned in the Xcode 4.4 release notes?

I've got question about @[] and @{}.

Some code taken from internet:

self.searches = [@[] mutableCopy]; 
self.searchResults = [@{} mutableCopy]; 
  1. Is @[] equal to [NSMutableDictionary dictionary]?
  2. Is @{} equal to [NSMutableArray array]?
like image 312
Tomasz Szulc Avatar asked Nov 28 '12 14:11

Tomasz Szulc


1 Answers

  1. No. @[] is equal to [NSArray array] or [[NSArray alloc] init].
  2. No. @{} is equal to [NSDictionary dictionary] or [[NSDictionary alloc] init].

(depending on the context and whether you use Automatic Reference Counting (ARC) or not)

That's why you see things like [@[] mutableCopy] sometimes. This will create an empty immutable array and create a mutable copy of it.

The result is the same as using [NSMutableDictionary dictionary] or [[NSMutableDictionary alloc] init].

like image 118
DrummerB Avatar answered Oct 05 '22 12:10

DrummerB