SugarRecord icon indicating copy to clipboard operation
SugarRecord copied to clipboard

"Serious application error" when CoreDataObservable used

Open krasnodar95 opened this issue 7 years ago • 0 comments

What

I got an error when using CoreDataObservable

[error] error: Serious application error.  An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:.  -[UICollectionViewUpdateItem _isCell]: unrecognized selector sent to instance 0x600000226a80 with userInfo (null)
CoreData: error: Serious application error.  An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:.  -[UICollectionViewUpdateItem _isCell]: unrecognized selector sent to instance 0x600000226a80 with userInfo (null)

Context

When the some data come in modifications section in method update (deletions: [Int], insertions: [(index: Int, element: T)], modifications: [(index: Int, element: T)])

Proposal

I think that the problem in CoreDataObservable in this code

    // MARK: - NSFetchedResultsControllerDelegate
    
    public func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
        switch type {
        case .delete:
            self.batchChanges.append(.delete(indexPath![0], anObject as! T))
        case .insert:
            self.batchChanges.append(.insert(newIndexPath![0], anObject as! T))
        case .update:
            self.batchChanges.append(.update(indexPath![0], anObject as! T))
        default: break
        }
    }

You use the index 0, which is the index of the section and not of the cell

krasnodar95 avatar May 20 '17 13:05 krasnodar95