Is there a difference between
NSArray *myArray = @[objectOne, objectTwo, objectThree];
and
NSArray *myArray = [NSArray arrayWithObjects:objectOne, objectTwo, objectThree, nil];
Is one preferred over the other?
Is there a difference between
NSArray *myArray = @[objectOne, objectTwo, objectThree];
and
NSArray *myArray = [NSArray arrayWithObjects:objectOne, objectTwo, objectThree, nil];
Is one preferred over the other?
They are almost identical, but not completely. The Clang documentation on Objective-C Literals states:
So
would throw a runtime exception if
objectTwo == nil
, butwould create an array with one element in that case.