Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Objective-C's new literal syntax mimic the addObject?

I know that I can do this to :

NSMutableArray *objects = [@[objectOne, objectTwo] mutableCopy];
NSObject *someObject = [NSObject new];
objects[0] = someObject;

But is there a way for the new literal syntax to mimic addObject:?

like image 684
Matt Foley Avatar asked Mar 22 '13 16:03

Matt Foley


1 Answers

As I was writing this, I tried out this bit of code and it worked like a charm. It isn't exactly documented, but I think this is a safe way to handle addObject: with the new literal syntax.

NSMutableArray *objects = [@[] mutableCopy];
NSObject *someObject = [NSObject new];
objects[objects.count] = object;
like image 79
Matt Foley Avatar answered Nov 04 '22 04:11

Matt Foley