是否可以在不觸發處理程序的情況下更改NSManagedObjectContextObjectsDidChangeNotification處理程序中的託管對象的屬性? 我從我們的服務器獲取數據,RestKit將數據映射到核心數據。數據到達我的數據庫後,我必須更改一些屬性。 感謝您的幫助。核心數據:更改NSManagedObjectContextObjectsDidChangeNotification中的對象
編輯: 這是我的代碼。該handleDidChangeNotification
方法被稱爲在一個週期:
- (void)addMyObserver
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleDidChangeNotification:)
name:NSManagedObjectContextObjectsDidChangeNotification
object:self.objectManager.managedObjectStore.mainQueueManagedObjectContext];
}
- (void)handleDidChangeNotification:(NSNotification *)notification
{
NSSet *updatedObjects = [[notification userInfo] objectForKey:NSUpdatedObjectsKey];
NSSet *deletedObjects = [[notification userInfo] objectForKey:NSDeletedObjectsKey];
NSSet *insertedObjects = [[notification userInfo] objectForKey:NSInsertedObjectsKey];
// modifiedObjects with store entity:
NSSet *modifiedObjects = [updatedObjects setByAddingObjectsFromSet:insertedObjects];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF isKindOfClass: %@", [MyStore class]];
NSSet *modifiedStoreObjects = [modifiedObjects filteredSetUsingPredicate:predicate];
if (modifiedStoreObjects.count > 0)
{
[modifiedStoreObjects enumerateObjectsUsingBlock:^(MyStore *store, BOOL *stop)
{
store.distanceValue = 1000;
}];
}
}
您是否考慮過使用單獨的MOC進行導入?這樣你就可以觀察到這個環境來做出這個改變。 – paulbailey