我注意到这种方法有一些意想不到的行为,并且想知道是否有人有任何见解。当我调用 removeObjectForKey
,我注意到 [setObject: obj ForKey: key]
实际上是在幕后调用的。我遇到了问题,因为我已经覆盖了这个方法 (setObject forKey
) 为 NSUserDefaults
.removeObjectForKey
的文档说:
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.
究竟什么是应用程序域,这可能是
setObject
的原因吗?被调用?我很困惑,因为我试图从 NSUserDefaults
中删除NSDictionary
,而不是为其设置对象。
最佳答案
我不会覆盖 setObject:forKey
对于 NSUserDefaults
.似乎是一个非常糟糕的主意。对于它的值(value),setObject:forKey
可能会使用 nil 值调用以删除 key 。
关于ios - NSUserDefaults removeObjectForKey,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36519259/