Xcode 7 beta 6 and and NSFetchedResultsController gave me headache today. If I compile same(with Swift 2 fixes) code with Xcode 6, program works on device and simulators(iOS 7,
I have tried several things and I believe this is a bug. As you can see from my log, even though I update existing record, delegate gets Insert Message. Adding conditional check at .Insert
fixed my issue. I am not using any move operation in the table. Therefore same kind of conditional operation maybe necessary as well if you are using .Move
My Current code is like below
func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {
switch type {
case .Insert:
//FIXME: iOS 9 Bug!
if indexPath != newIndexPath {
tableView.insertRowsAtIndexPaths([newIndexPath!], withRowAnimation: .Fade)
}
case .Delete:
tableView.deleteRowsAtIndexPaths([indexPath!], withRowAnimation: .Fade)
case .Update:
tableView.reloadRowsAtIndexPaths([indexPath!], withRowAnimation: .Fade)
// self.configureCell(tableView.cellForRowAtIndexPath(indexPath!)!, atIndexPath: indexPath!)
case .Move:
tableView.deleteRowsAtIndexPaths([indexPath!], withRowAnimation: .Fade)
tableView.insertRowsAtIndexPaths([newIndexPath!], withRowAnimation: .Fade)
}
}
I have tried to update single record, multiple records and I haven't seen any crashes yet so far. I am using
tableView.reloadRowsAtIndexPaths([indexPath!], withRowAnimation: .Fade)
method but
self.configureCell(tableView.cellForRowAtIndexPath(indexPath!)!, atIndexPath: indexPath!)
also worked during my tests.