There is a literal syntax to add object and change object in an NSMutableDictionary, is there a literal syntax to remove object?
Is there NSMutableDictionary literal syntax to remove an element?
1.6k Views Asked by Boon At
3
There are 3 best solutions below
0
On
As of iOS 9 and macOS 10.11, these two are equivalent:
[dictionary removeObjectForKey:@"key"];
dictionary[@"key"] = nil;
See the Foundation release notes (search for the heading NSMutableDictionary subscript syntax change).
Yes, but... :-)
This is not supported by default, however the new syntax for setting dictionary elements uses the method
setObject:forKeyedSubscript:rather thansetObject:forKey:. So you can write a category which replaces the former and either sets or removes the element:Add that to your application and then:
will remove an element.