3lvis / DATASource

Core Data's NSFetchedResultsController wrapper for UITableView and UICollectionView
Other
106 stars 27 forks source link

Predicate update for DATASource cause crash #104

Closed tibibo closed 7 years ago

tibibo commented 7 years ago

In case the new predicate change amount of items, collection view crashed:

2017-05-12 11:23:26.192 SwiftDemo[12755:330575] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (14) must be equal to the number of items contained in that section before the update (16), plus or minus the number of items inserted or deleted from that section (10 inserted, 10 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'

To repeat this issue just add to Swift Demo project inside one of CollectionViewController:

func saveAction() {
        Helper.addNewUser(dataStack: self.dataStack)
        self.dataSource.predicate = NSPredicate(format: "role == %@", "manager")
 }

Possible solution (rollback "Safer UICollection reloading") in Merge Request — https://github.com/SyncDB/DATASource/pull/103

3lvis commented 7 years ago

Thanks for suggesting this fix, @tibibo I'll check it out.

Have a nice weekend :)

3lvis commented 7 years ago

Merged https://github.com/SyncDB/DATASource/pull/103