Подтвердить что ты не робот

NSFetchedResultsController вызывает didChangeObject delete вместо обновления

Это код, я сохраняю модель через Magical Record:

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

Вызывается вызов вместо обновления после вызова вышеописанного кода:

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
    }
}

Это происходит только в том случае, если я задаю предикат для запроса выборки, например:

fetchRequest.predicate = NSPredicate(format:"user == john")
4b9b3361

Ответ 1

Что здесь происходит, так это то, что вместо ожидаемого события изменения NSFetchedResultsChangeUpdate вы получаете NSFetchedResultsChangeDelete, за которым следует NSFetchedResultsChangeInsert. Вы также можете увидеть NSFetchedResultsChangeMove с тем же indexPath, что и источник и получатель. Это известная проблема в несколько бета-версий iOS 9 22380191 и другие.