Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.

Fix batch updates with NSFetchedResultsController assertions#295

Merged
steipete merged 4 commits intosteipete:masterfrom
aburgel:move_fixes
Apr 17, 2013
Merged

Fix batch updates with NSFetchedResultsController assertions#295
steipete merged 4 commits intosteipete:masterfrom
aburgel:move_fixes

Conversation

@aburgel
Copy link
Copy Markdown
Contributor

@aburgel 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 4 commits April 16, 2013 19:31
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.
@aburgel
Copy link
Copy Markdown
Contributor Author

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.

@steipete
Copy link
Copy Markdown
Owner

Looks all good to me - thanks!

steipete added a commit that referenced this pull request Apr 17, 2013
Fix batch updates with NSFetchedResultsController assertions
@steipete steipete merged commit cc7c705 into steipete:master Apr 17, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants