سؤال

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:?

هل كانت مفيدة؟

المحلول

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;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top