ios - Is -[NSDictionary setObject:nil forKey:] the same as -[NSDictionary removeObjectForKey:]? -
ios - Is -[NSDictionary setObject:nil forKey:] the same as -[NSDictionary removeObjectForKey:]? -
i'm reading through source code , noticed next api, developer passes in nil
if want object removed.
- (void)setsomestatus:(somestatusobject *)status { if (status != nil) { [store setobject:status forkey:some_status_key]; } else { [store removeobjectforkey:some_status_key]; } }
my specific question if above can reduced to
- (void)setsomestatus:(somestatusobject *)status { [store setobject:status forkey:some_status_key]; }
or alternatively
- (void)setsomestatus:(somestatusobject *)status { store[some_status_key] = status; }
no, not equivalent. in fact, passing nil
setobject:forkey:
(either value or key) result in runtime exception.
ios objective-c nsdictionary
Comments
Post a Comment