Is there a literal syntax for mutable collections?
But, is there a literal syntax for creating an NSMutableArray or an NSMutableDictionary?
No. Best alternative:
[@[ @"foo", @"bar"] mutableCopy]
There isn't a built in way, but I just usually use mutableCopy
like this:
NSMutableArray *array = [@[ @"1", @"2", @"3" ] mutableCopy];
Yes. But not quite. Take a look at this;
NSMutableArray *list = [@[] mutableCopy];
This creates a non-mutable array @[]
and calls mutableCopy
which returns a NSMutableArray *
. In place of @[]
, you can give any array literal.
No. Just as how there isn't a syntax for creating an NSMutableString
either. Mutable objects are not particularly suited to literal values.