In Cocoa KVO, why doesn't a change on a NSMutableArray proxy notify observers?

这一生的挚爱 提交于 2019-11-30 20:31:46

It turns out that mutableArrayValueForKey: does not always return a notifying array. It only does so when observers have already been registered on the observed object!

So swapping my first two lines fixes the problem:

[[DocumentsManager instance] addObserver:self forKeyPath:@"documents" options:NSKeyValueObservingOptionNew context:NULL];
NSMutableArray *docsProxy = [[DocumentsManager instance] mutableArrayValueForKey:@"documents"];

Can't help thinking how much time we'd save if we could read the source code of those methods…

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!