NSFetchedResultsController updating with wrong update type

∥☆過路亽.° 提交于 2019-12-01 07:44:09

问题


Please see the comments before blindly voting this as a duplicate. It isn't a duplicate question.

First - I'm using MagicalRecord for core data. Second - My UICollectionView is populated with an NSFetchedResultsController.

The NSPredicate for the NSFetchedResultsController is ...

NSPredicate *eventPredicate = [NSPredicate predicateWithFormat:@"event = %@", self.event];
NSPredicate *deletedPredicate = [NSPredicate predicateWithFormat:@"deleted == NO"];

NSPredicate *compoundPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[eventPredicate, deletedPredicate]];

When I add new items to CoreData using Magical Record's saveWithBlock the collectionView updates properly and animates the changes into view.

The problem is that when I change the value of deleted to @YES...

[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
    Photo *photo = [[self photoAtIndexPath:[self.collectionView indexPathForCell:cell]] inContext:localContext];
    photo.deleted = @YES;
}];

Then the NSFetchedResultsController delegate methods fire except it fires with the change type NSFetchedResultsChangeUpdate. This isn't what it should be though. It should be NSFetchedResultsChangeDelete as changing the value of deleted should remove it from the fetch request.

I don't want to just delete the object as I need to update a server with the deleted ID.

Also, if I then pop the view and push it back again the photo is gone so I know it is updating it properly and I know it's removing it from the fetch request.

Any ideas?


回答1:


You must not call an attribute "deleted", because that conflicts with the isDeleted method of NSManagedObject.

See Core Data NSPredicate "deleted == NO" does not work as expected or NSPredicate does not get executed on first launch for different examples that "strange things" happen if an attribute is called "deleted".



来源:https://stackoverflow.com/questions/16283252/nsfetchedresultscontroller-updating-with-wrong-update-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!