Use `setValue:forKey:` instead of `setObject:forKey` if value can be nil
If you want to add values to an NSMutableDictionary but you can't be sure that all the values are not nil use setValue:forKey
instead of setObject:forKey:
because
This method adds value and key to the dictionary using
setObject:forKey:
, unless value is nil in which case the method instead attempts to remove key usingremoveObjectForKey:
.
(from the Documentation of NSMutableDictionary)
Written by dasdom
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Objective-c
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#