Yes, but ... :-)
This is not supported by default, but the new syntax for setting dictionary items uses the setObject:forKeyedSubscript: method, and not setObject:forKey: Thus, you can write a category that replaces the former, and either installs or removes the item:
@implementation NSMutableDictionary (RemoveWithNil) - (void) setObject:(id)obj forKeyedSubscript:(id<NSCopying>)key { if (obj) [self setObject:obj forKey:key]; else [self removeObjectForKey:key]; } @end
Add this to your application and then:
dict[aKey] = nil;
will delete the item.
source share