Hello, I’ve seen your priceless tutorial videos for CoreData and I’m a big fan of yours
BTW, I have a question for this last tutorial lecture.
Do you have any sample project for this course that implements insertion/deletion Friend objects using NSFetchedResultsControllerDelegate in MainViewController? I’ve tried to implement this, but this is quite hard for me due to sections .
When I implement insertion/deletion using NSFetchedResultsControllerDelegate and run the app, it crashes when I add a new friend object I have no idea why this crash occurs. Do you have an idea or reference that I can refer?
This is the code for insertion/deletion a friend object using NSFetchedResultsControllerDelegate:
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
switch type {
case .insert:
guard let indexPathForInsertion = newIndexPath else {
return
}
if indexPathForInsertion.section > collectionView.numberOfSections - 1 {
let indexSet = IndexSet(integer: indexPathForInsertion.section)
collectionView.insertSections(indexSet)
collectionView.insertItems(at: [indexPathForInsertion])
}
case .delete:
guard let indexPathForDeletion = indexPath else {
return
}
if collectionView.numberOfItems(inSection: indexPathForDeletion.section) == 1 {
collectionView.deleteSections(IndexSet(integer: indexPathForDeletion.section))
}
else {
collectionView.deleteItems(at: [indexPathForDeletion])
}
case .move, .update:
break
}
}
And the error message is:
error: Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. -[UICachedDeviceRGBColor compare:]: unrecognized selector sent to instance 0x600000261200 with userInfo (null) CoreData: error: Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. -[UICachedDeviceRGBColor compare:]: unrecognized selector sent to instance 0x600000261200 with userInfo (null)