NSManagedObject的hasChanges为true,而changedValues为空 [英] NSManagedObject's hasChanges is true while changedValues is empty
问题描述
我正在尝试观察NSManagedObjectContextWillSaveNotification
上各个NSManagedObject
的变化:
I am trying to observe individual NSManagedObject
changes on NSManagedObjectContextWillSaveNotification
:
- (void)managedObjectContextWillSave:(NSNotification *)notification
{
for (NSManagedObject * object in self.mutableObservedManagedObjects)
{
if (object.hasChanges)
{
[self managedObjectWasUpdated:object];
}
}
}
问题在于hasChanges
为真而object.changedValues
为空,因此错误地(?)触发了managedObjectWasUpdated:
.
The problem is that hasChanges
is true while object.changedValues
is empty, thus wrongly (?) triggering managedObjectWasUpdated:
.
我试图理解为什么会这样,如果我最好在致电managedObjectWasUpdated:
之前检查object.changedValues.count
.
I'm trying to understand why this is the case and if I should better check object.changedValues.count
before calling managedObjectWasUpdated:
.
isInserted
和isDeleted
均为假.
推荐答案
我遇到了相同的问题.而不是获取标志,我只是检查changedValues()是否为空.
I encountered the same issue. Instead of getting the flags, I just checked if changedValues() is empty.
对于Swift:
if !managedObject.changedValues().isEmpty {
// Has some changed values
}
这篇关于NSManagedObject的hasChanges为true,而changedValues为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!