NSArray *keys = @[@"duration"];

I never saw such a terminology until now. I have a vague idea about this - but that's not enough. Who can translate this line of code into classical Objective-C code?


Thanks for helping

gefa

Accepted Answer

@[ … ] is an Objective-C array literal. It is similar to [NSArray arrayWithObjects:…, nil]. One difference is that +arrayWithObjects: considers the first nil it finds as the terminator. So, if you have variables in the list, like [NSArray arrayWithObjects:var1, var2, var3, nil] and var2 happens to be nil, your list will only be 1 element long. It will contain var1 and that's it.


By contrast, @[ … ] throws an exception if any of the elements in the list are nil. So, @[ var1, var2, var3 ] will throw an exception is var2 is nil. This is better.


Of course, the array literal syntax is also a lot nicer.

Thanks for your prompt reply.


Does there exist something like a dictionary where one can lookup 'synonyms' resp. 'new terminology' like these ones?

Unfortunately, Apple's manuals and guides often use the newest terminology without referring to older ones.


Best regards

gefa

NSArray *keys = @[@"duration"];
 
 
Q