Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fix batch updates with NSFetchedResultsController assertions #295

Merged
merged 4 commits into from Apr 17, 2013

Conversation

Projects
None yet
2 participants
Contributor

aburgel commented Apr 17, 2013

I've been attempting to use NSFetchedResultsController to update a PSTCollectionView, and its causing a bunch of assertions and errors. I've tackled some here, but there's at least one more to fix.

Here's a run down of what I've done so far:

  1. Fixed a spelling error in the assertion message (might as well).
  2. The first assertion you get when batching moves and deletes is on line 1871. I think the assertion needs to be negated. You want to assert that no moves and deletes occur on the same item.
  3. Once that's fixed, you get array out of bounds exceptions at line 2043. Since deletes happens before moves, the index of the move operation is no longer valid. I fixed this by doing indexOfObject instead of objectAtIndex since we know what the object is. Not 100% sure about this, but it works in my case.

The next issue (hopefully the last) has to do with mixing reloads and deletes. A reload is implemented as a delete and insert. If that is mixed with other deletes, then again the indexes become invalid. I think it might be easier to just keep these as a reload operation, but I'm not sure what constitutes a reload.

Is calling [PSTCollectionView createPreparedCellForItemAtIndexPath:withLayoutAttributes:] sufficient?

aburgel added some commits Apr 16, 2013

Fix move operations when batched with deletes
Since deletes happen before moves, indexPathBeforeUpdate.item may no
longer point to correct index, so search for the object we're looking
for and use its index.
Contributor

aburgel commented Apr 17, 2013

I added a test app based off the CircleLayout app. It runs random batches of inserts, moves, reloads, and deletes.

Its not very well written and since its random, it can be hard to reproduce specific issues, so maybe its not all that useful ;-). But it does show the bugs, especially when you run it using Apple's code, which doesn't crash, but still shows some weird behavior.

Owner

steipete commented Apr 17, 2013

Looks all good to me - thanks!

steipete added a commit that referenced this pull request Apr 17, 2013

Merge pull request #295 from aburgel/move_fixes
Fix batch updates with NSFetchedResultsController assertions

@steipete steipete merged commit cc7c705 into steipete:master Apr 17, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment