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

php - How to pass multiple values from url -

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

database - php search bar when I press submit with nothing in the search bar it shows all the data -