2

我在使用 CoreData + iCloud 同步时遇到问题。

有时,通知 NSPersistentStoreDidImportUbiquitousContentChangesNotification 在 Inserted、Updated 和 Deleted 中返回一个空数组。

如果在发生更改时调用此通知,为什么返回一个空通知?

谢谢!!!

调用通知的代码:

 - (void)persistentStoreDidChange:(NSNotification*)notification
 {
     DLog(@"Change Detected! Notification: %@", notification.description)

     [__managedObjectContext performBlockAndWait:^(void)
     {
         [__managedObjectContext mergeChangesFromContextDidSaveNotification:notification];

         for(id<CoreDataDelegate>delegate in _delegates)
         {
             if([delegate respondsToSelector:@selector(persistentStoreDidChange)])
                [delegate persistentStoreDidChange];

         }
     }];
 }
4

1 回答 1

3

它只是有时这样做。与 iCloud 与 Core Data 的许多严重问题相比,这是一个非常小的问题。

收到此通知时,我喜欢做的是首先检查插入、更新和删除的对象,然后不要继续进行合并过程,除非你发现了什么。做类似的事情

NSDictionary *userInfo = [notification userInfo];
if (([userInfo objectForKey:NSInsertedObjectsKey] > 0) || 
    ([userInfo objectForKey:NSUpdatedObjectsKey] > 0) || 
    ([userInfo objectForKey:NSDeletedObjectsKey] > 0)) 
{
    // merge...
}
于 2013-07-19T16:38:08.597 回答