iOS 9 CoreData NSFetchedResultsController update causes blank rows in UICollectionView/UITableView

Description:

I have separate classes that run NSFetchedResultsController on both UITableView and UICollectionView. They've been working in iOS 8. Since iOS 9, I occasionally get the console error below on NSManagedObject updates. The changes to NSManagedObject is valid and saves properly to persistent store. However, the UI for UITableView/UICollectionView backed by the NSFetchedResultsController breaks and shows blank rows.


Console:

Assertion failure in -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:]

CoreData: error: Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. attempt to delete and reload the same index path (<NSIndexPath: 0xc000000000400016> {length = 2, path = 0 - 2}) with userInfo (null)


Update:

iOS9 Beta 2 not fixed and no solution yet, but below's the line that's causing the trouble:


self.tableView.reloadRowsAtIndexPaths()


Seems like it's having trouble reloading cells on updates.


Update 2:

iOS9 Beta 3 still broken.

The root cause of all this is during the NSFetchedResultsController's delegate call for an update, NSFetchedResultsChangeMove and NSFetchedResultsChangeUpdate are both called. Not sure if this use to happen in iOS 8 and prior but just didn't throw off errors.


Update 3:

Issue fixed once updated to iOS 9 Beta 5

I'm experiencing the same issue. Hopefully it will be solved in the next beta.

I'm experiencing the same issue. I also hope this gets fixed.

ya FRC is very buggy on xcode beta 4

i confirm that this bug still exist in xcode beta 5

Some folks are reporting the issue being fixed, but I see Netherlol is having it still. If you're running Xcode 7.0 Beta 5 and you're still seeing this issue, please file a bug report and post the report number here. If you can attach a project in which the error is reproduced, it does help tremendously. You can also include the link to this conversation in the bug report, it helps by adding context.

its any update to coredata really, and i get the follow error:


CoreData: error: Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (12) must be equal to the number of rows contained in that section before the update (12), plus or minus the number of rows inserted or deleted from that section (2 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out). with userInfo (null)

what i did ? nothing really just a simple update to the activity object when someone click on like button:

activity.liked = !activity.liked.boolValue

activity.likesCount = activity.likesCount.integerValue + 1


ps: this only happends on ios 8.4 when compile with xcode 7, with xcode 6 works fine, and ios 9 with fine as well.

it seems like the same problem as this guy https://forums.developer.apple.com/message/29866#29866


Radar fired with number: 22205376

In the NSFetchedResultsChangeUpdate case I was previously able to get the updated object from the fetched results controller to update the table view cell, something like:


NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath]


With beta 5 this is now broken (I get the wrong object) compared to the behavior in iOS 8.


I do get the updated object correctly from the fetched results controller delegate, so I was able to work around. 🙂

Onit, would you file a bug report with a concise sample project, where it works on beta 4 but doesn't work on beta 5?

It'd be quick and easy to take a look at this if you could attach a sample project (or actual project) to your bug report. The inclusion of sample projects with reproducable issues serve to eliminate a lot of guesswork and expidite the process -- super helpful stuff.


Let me know (and update your bug report) with this:

Xcode version: (eg: Xcode 7 beta 5)

Deployment Target: (eg: iOS 8.4)

Simulator or Device OS: (eg: iOS 9)


If you're using Xcode 7 and 6 and have different results for iOS 8.4 only, then fill out two of those in your reply.

If you are able to attach a sample project that works under Xcode 6/8.4/8.4 and doesn't work under Xcode 7/8.4/9.0 or Xcode 7/8.4/8.4, please include it on your bug report too.

App SDK / Frameworks are a good choice, if you have that. It's better to file a bug report but get it in the wrong component than to not file it at all. Once it's in the system, someone will read it and update the component so it gets routed in the right direction.

Hi Vlas -- Have you had the opportunity to see if the problem persists in Beta 5?

On the latest beta I am getting an NSFetchedResultsChangeMove with same new and old index, but would expect an NSFetchedResultsChangeUpdate.

Same here,

prior to beta 5 I was getting both Move (from/to index the same) and Update. As of beta 5 I only get Move (from/to index the same). As a result my UI cannot be updated if managed object changes because there's no update event to pass to collectionview.

I'm still seeing this in CoreStore's demo app as of XCode 7 beta 5.

Filed as rdar://22380191

Did anyone uploaded a sample project?

I'm having the same issue. Should I prepare sample project for that or it is already handled?

iOS 9 CoreData NSFetchedResultsController update causes blank rows in UICollectionView/UITableView
 
 
Q