Implementing NSFetchedResultsController

NSFetchedResultsController is a helper object that specializes in fetching data and managing this data. It listens to changes in its managed object context and notifies a delegate whenever the data it has fetched changes. This is incredibly helpful because it allows you to respond to specific changes in the dataset rather than reloading the table view entirely.

Being a delegate for the fetched results controller involves the following four important methods:

  • controllerWillChangeContent(_:)
  • controllerDidChangeContent(_:)
  • controller(_:didChange:at:for:newIndexPath:)
  • controller(_:didChange:atSectionIndex:for:)

The first method, controllerWillChangeContent(_:), is called right before the controller passes ...

Get Mastering iOS 12 Programming - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.