观察NSManagedObject属性的变化:如何避免循环? [英] Observing changes in the properties of an NSManagedObject: how to avoid looping?
问题描述
在我的应用程序中,我观察被管对象的属性。更改可能导致对其某些其他属性的调整,因此受管对象本身会接收到已更改属性的消息。这些更改通过在Interface Builder中设置的绑定实现。
In my application, I observe the properties of a managed object. A change may lead to adjustments in some of its other properties, so the managed object itself receives a message of a changed property. These changes happen through bindings that are set up in the Interface Builder.
我在托管对象的实现中有以下方法:
I have the following method in the implementation of the managed object:
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ( !processingChange )
{
processingChange = YES;
*** DO STUFF TO THIS MANAGED OBJECT'S PROPERTIES ***
[self.managedObjectContext processPendingChanges];
processingChange = NO;
return;
}
}
processingChange
boolean是为了避免一个无尽的通知循环,但它不工作,因为我期望(加上它看起来像一个真正的脏黑客)。
The processingChange
boolean is there to avoid an endless "notification loop", but it is not working as I expect (plus it looks like a real dirty hack).
必须有另一种方法来做到这一点。任何建议?
There must be another way to do this. Any suggestions?
推荐答案
使用MOMs setPrimitiveValue:forKey:
生成KVO
use MOMs' setPrimitiveValue:forKey:
it doesnt generate KVOs
这篇关于观察NSManagedObject属性的变化:如何避免循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!