Last Updated: September 09, 2019
·
5.066K
· dasdom

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 using removeObjectForKey:.

(from the Documentation of NSMutableDictionary)