Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a literal syntax for mutable collections?

I know I can create an NSArray with @[@"foo", @"bar"] or an NSDictionary with @{@0 : @"foo", @1 : @"bar"}.

Is there a literal syntax for creating an NSMutableArray or an NSMutableDictionary?

like image 992
ma11hew28 Avatar asked Sep 14 '12 01:09

ma11hew28


2 Answers

There isn't a built in way, but I just usually use mutableCopy like this:

NSMutableArray *array = [@[ @"1", @"2", @"3" ] mutableCopy]; 
like image 187
danielbeard Avatar answered Sep 23 '22 13:09

danielbeard


No. Just as how there isn't a syntax for creating an NSMutableString either. Mutable objects are not particularly suited to literal values.

like image 24
Lily Ballard Avatar answered Sep 23 '22 13:09

Lily Ballard