NSFetchedResultsController调用didChangeObject删除而不是更新

vbu*_*vic 20 core-data nsfetchedresultscontroller ios magicalrecord swift

这是代码,我通过魔法记录保存模型:

MagicalRecord.saveWithBlock({ (localContext) -> Void in
                    var localNotification = CDNotification.MR_findFirstByAttribute("notificationID", withValue: notification.notificationID, inContext: localContext) as CDNotification
                    localNotification.readNumber = NSNumber(bool: true)
                })
Run Code Online (Sandbox Code Playgroud)

调用上面的代码后,调用Delete而不是update:

func controller(controller: NSFetchedResultsController, didChangeObject object: AnyObject, atIndexPath indexPath: NSIndexPath, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath) {
    switch type {
    case NSFetchedResultsChangeType.Insert:
        self.tableView.insertRowsAtIndexPaths([newIndexPath], withRowAnimation: .Fade)
    case NSFetchedResultsChangeType.Update:
        if let cell = self.tableView.cellForRowAtIndexPath(indexPath){
            self.configureCell(cell as TableViewCell, atIndexPath: indexPath, withNotification: object as CDNotification)
        }
        self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
    case NSFetchedResultsChangeType.Move:
        self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
        self.tableView.insertRowsAtIndexPaths([newIndexPath], withRowAnimation: .Fade)
    case NSFetchedResultsChangeType.Delete:
        self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
    default:
        return
    }
}
Run Code Online (Sandbox Code Playgroud)

只有在我为获取请求设置谓词时才会发生这种情况,例如:

fetchRequest.predicate = NSPredicate(format:"user == john")
Run Code Online (Sandbox Code Playgroud)

que*_*ish 5

这里发生的事情是,而不是NSFetchedResultsChangeUpdate你期望的变化事件,你得到一个NSFetchedResultsChangeDelete跟随NSFetchedResultsChangeInsert.您可能还会看到NSFetchedResultsChangeMove与源和目标相同的indexPath.这是iOS 9 22380191几个测试版中的已知问题.