Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in YPLibrary+LibraryChange.swift #325

Closed
Out1and3r opened this issue Mar 28, 2019 · 3 comments
Closed

Crash in YPLibrary+LibraryChange.swift #325

Out1and3r opened this issue Mar 28, 2019 · 3 comments

Comments

@Out1and3r
Copy link

Out1and3r commented Mar 28, 2019

Describe the bug
Fatal Exception:
NSInternalInconsistencyException attempt to delete and reload the same index path (<NSIndexPath: 0x2800dfa60> {length = 2, path = 0 - 0}) closure #1 in YPLibraryVC.photoLibraryDidChange(_:)

Expected behavior
Library should not crash

Environment (please complete the following information):

  • Device: iPhone X
  • OS: 12.1.4
  • Xcode Version 10.1
  • Swift Version 4.2

Installation Type

  • Cocoapods

Additional context
Block

collectionView.performBatchUpdates({
                        let removedIndexes = collectionChanges!.removedIndexes
                        if (removedIndexes?.count ?? 0) != 0 {
                            collectionView.deleteItems(at: removedIndexes!.aapl_indexPathsFromIndexesWithSection(0))
                        }
                        let insertedIndexes = collectionChanges!.insertedIndexes
                        if (insertedIndexes?.count ?? 0) != 0 {
                            collectionView.insertItems(at: insertedIndexes!.aapl_indexPathsFromIndexesWithSection(0))
                        }
                        let changedIndexes = collectionChanges!.changedIndexes
                            if (changedIndexes?.count ?? 0) != 0 {
                                collectionView.reloadItems(at: changedIndexes!.aapl_indexPathsFromIndexesWithSection(0))
                            }
                    }, completion: nil)

Should be changed to

collectionView.performBatchUpdates({
                        let removedIndexes = collectionChanges!.removedIndexes
                        if (removedIndexes?.count ?? 0) != 0 {
                            collectionView.deleteItems(at: removedIndexes!.aapl_indexPathsFromIndexesWithSection(0))
                        }
                        let insertedIndexes = collectionChanges!.insertedIndexes
                        if (insertedIndexes?.count ?? 0) != 0 {
                            collectionView.insertItems(at: insertedIndexes!.aapl_indexPathsFromIndexesWithSection(0))
                        }
                        
                    }, completion: { (finished) in
                        if finished {
                            let changedIndexes = collectionChanges!.changedIndexes
                            if (changedIndexes?.count ?? 0) != 0 {
                                collectionView.reloadItems(at: changedIndexes!.aapl_indexPathsFromIndexesWithSection(0))
                            }
                        }
                    })
@victormihaita
Copy link

We have the same issue in our project ☝️

@s4cha
Copy link
Member

s4cha commented Apr 28, 2019

@Out1and3r Nice catch and Kudos for providing a working fix, this much much appreciated 👏
This will be in the next (swift 5) version.
I will ping when up :)

@s4cha
Copy link
Member

s4cha commented Apr 28, 2019

@s4cha s4cha closed this as completed Apr 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants