Chapter 5: NSFetchedResultsController - delete a team

Hello @pietrorea, I have extended World Cup! app for deleting team. It works but is it possible to make it more straight with NSFetchedResultsController? I have added these 2 functions in extension ViewController: UITableViewDelegate { … }

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true


func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
let teamToRemove = fetchedResultsController.object(at: indexPath)

@pietrorea Can you please help with this when you get a chance? Thank you - much appreciated! :]

@internetstream Thanks very much for your question! May I ask what you mean by “more straight”? If you mean by that, better architecture, then you should follow the example in the book, and use the NSFetchResultsController delegate methods.


func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {

func controller(_ controller: NSFetchedResultsController<NSFetchRequestResults>, didChange anObject: AnyObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {


I hope this helps!

All the best.

This topic was automatically closed after 166 days. New replies are no longer allowed.