Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一段代码可能会触发两次相同的注册过程。这是相当做作的,所以我宁愿没有办法手动检查注册是否发生。但是,如果不允许多次注册相同的 KVO 关系,有人可以建议一种方法来检测对象是否已经有效地向另一个观察者注册了某个键路径?
它是安全的。您的
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
只会被多次调用。如果你不想这样,你可以尝试删除观察者,然后再添加它。