What object does @ [obj1, obj2] create?

I came across the following:

NSArray *array = @[object1, object2]; 

It seems NSArray is being created, but is this array instance an auto-implemented object or should I let it go?

+7
source share
2 answers

This is a new collection literal available in the compiler, which ships with code xcode 4.4 and higher

 @[object1, object2]; 

equivalently

 [NSArray arrayWithObjects:object1, object2, nil]; 

so yes, this is an auto-implemented object, if you need it to be saved, you can do

 myRetainedArray = [@[object1, object2] retain]; 

this question contains a good description of all new literals

+9
source

This is the new llvm compiler for creating an array. The compiler will change this value to:

 NSArray *array = [NSArray arrayWithObjects: object1,object2,nil]; 

Thus, it returns an object with auto-implementation.

The Google search engine has additional information:

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

0
source

All Articles