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

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -