Reputation: 101
I've noticed some unexpected behavior with this method, and was wondering if anyone had any insight. When I call removeObjectForKey
, I have noticed that [setObject: obj ForKey: key]
is actually called behind the scenes. I'm running into problems because I have overwritten this method (setObject forKey
) for NSUserDefaults
.
The documentation of removeObjectForKey
says:
Removing a default has no effect on the value returned by the
objectForKey:
method if the same key exists in a domain that precedes the standard application domain in the search list.
What exactly is an application domain, and could this be the reason why setObject
is being called? I'm confused because I'm trying to remove from the NSUserDefaults
NSDictionary
, not set an object to it.
Upvotes: 1
Views: 358
Reputation: 9768
I wouldn't override setObject:forKey
for NSUserDefaults
. Seems like a really bad idea. For what it's worth, setObject:forKey
is probably being called with a nil value to delete the key.
Upvotes: 2