I'm using a NSFetchedResultsController to display my core data and I also have a user generated images in a ubiquitous documents container, for each managed object the fetchedResultsController displays.
I've implemented the swipe left to delete functions on the TableView, but I'm having trouble accessing the managed object before the fetchedResultsController deletes my object. I need this access to also delete the user generated images in my iCloud container.
Here's the function I'm using:
func controller(controller: NSFetchedResultsController!, didChangeObject anObject: AnyObject!, atIndexPath indexPath: NSIndexPath!, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath!) {
switch type
{
case .Insert:
tableView.insertRowsAtIndexPaths([newIndexPath], withRowAnimation: .Automatic)
case .Delete:
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
default:
break
}
}
I've ran tests and I can't reference to the deleted object using anObject, indexPath or newIndexPath.
Any assistance will be greatly appreciated! Thanks, Garret
Why is the controller responsible for deleting the data? If other controllers delete managed objects, they have to implement image deletion too? Hardly a good solution.
I think it would make much more sense to intercept the deletion in the managed object subclass and make sure the image is deleted as well. You can use the managed objects's prepareForDeletion
hook.