jflinter / Dwifft

Swift Diff

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CollectionViewDiffCalculator crashes every time

bondareb-evgenii opened this issue · comments

commented

Fix taken from here: http://stackoverflow.com/questions/25265183/collectionview-performbatchupdates-crash

if oldRows.isEmpty {
collectionView?.reloadData()
}
else {
collectionView?.performBatchUpdates({ () -> Void in
self.collectionView?.insertItemsAtIndexPaths(insertionIndexPaths)
self.collectionView?.deleteItemsAtIndexPaths(deletionIndexPaths)
}, completion: nil)
}

Can you provide a bit more context here? What version of iOS are you observing this crash on? Could you link to a small project that reproduces this? The fact that others have used this code safely makes me wonder about the actual root cause here.

I think this is the same general problem I mentioned in #23: UIKit expects the data source's counts to change within performBatchUpdates. I saw the same NSInternalInconsistencyException errors I documented in #23 with collection views.

I need to pull the latest master (and migrate to Swift 3.0), but I should be able to fix this by changing CollectionViewDiffCalculator to use a set block instead of didSet. set will calculate the diff and, if the diff introduces changes, call performBatchUpdates, update the data source, and request the add/remove animations.

Great, thanks Elliot - excited to see what you put together.

On Fri, Sep 16, 2016 at 1:10 AM, Elliott Williams notifications@github.com
wrote:

I think this is the same general problem I mentioned in #23
#23: UIKit expects the data
source's counts to change within performBatchUpdates. I saw the same
NSInternalInconsistencyException errors I documented in #23
#23.

I need to pull the latest master (and migrate to Swift 3.0), but I should
be able to fix this by changing CollectionViewDiffCalculator to use a set
block instead of didSet. set will calculate the diff and, if the diff
introduces changes, call performBatchUpdates, update the data source, and
request the add/remove animations.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#21 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAtM55g4coswufr6D0RzEdeVGOwEaZhzks5qqiTRgaJpZM4Jdfkj
.

This should be fixed in #27.