I have a dictionary and want to add a new object to it but compiler give error that it not mutable.
like code below:
dict[@"key"] = @"something new";
I have a dictionary and want to add a new object to it but compiler give error that it not mutable.
like code below:
dict[@"key"] = @"something new";
You are trying to mutate an immutable object. You need to create a mutable copy and the add the new key-value
NSMutableDictionary *mut = [dict mutableCopy];
mut[@"new key"] = @"new value";
If you want to keep the dictionary immutable, you can do:
NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:@"something new", @"key", nil];