Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix batch updates with NSFetchedResultsController assertions #295

Merged
merged 4 commits into from

2 participants

@aburgel

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
@aburgel aburgel Fix assertion on deleting and moving same item ef5c06b
@aburgel aburgel Fix assertion message typo 9bdeca7
@aburgel aburgel 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.
cc51db3
@aburgel aburgel Add batch update example app ea929dd
@aburgel

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
Owner

Looks all good to me - thanks!

@steipete steipete merged commit cc7c705 into steipete:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 16, 2013
  1. @aburgel
  2. @aburgel

    Fix assertion message typo

    aburgel authored
Commits on Apr 17, 2013
  1. @aburgel

    Fix move operations when batched with deletes

    aburgel authored
    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.
  2. @aburgel

    Add batch update example app

    aburgel authored
Something went wrong with that request. Please try again.