NSFetchedResultsController: The Bridge for Core Data & UI

NSFetchedResultsController is a bridge that automatically syncs a Core Data database with a UITableView. It efficiently manages data fetching, memory, and UI updates for dynamic lists, like a social feed.
WHY IT EXISTS Manually keeping a list UI in sync with a database is complex. You need to fetch data, listen for inserts, deletes, and updates, and then tell the UI exactly which rows to animate. This is error-prone and boilerplate-heavy. NSFetchedResultsController was created to automate this entire process for Core Data.
THE MENTAL MODEL Think of it as a stage manager for your UI. Your Core Data store is the script, and your UITableView is the stage. The NSFetchedResultsController watches the script for changes (data updates) and gives precise, animated directions to the actors on stage (the UI cells), so the show runs smoothly without manual intervention.
HOW IT WORKS You initialize an FRC with a fetch request, a managed object context, and optionally a key path for sectioning. After calling performFetch(), it populates its fetchedObjects property. You then set a delegate, which receives detailed notifications about data changes. These notifications tell you exactly what changed: an object was inserted, deleted, moved, or updated. You use these delegate callbacks to call the corresponding UITableView or UICollectionView methods (like insertRows, deleteRows) inside a batch update block.
WHEN TO USE IT Use it whenever you are displaying a list or grid of Core Data objects in a UITableView or UICollectionView. It is the standard, most efficient way to bind a dynamic Core Data query to the UI in Apple's frameworks. It's perfect for contact lists, message threads, or any feed-style interface.
WHEN NOT TO USE IT Don't use it if your data source is not Core Data. It's also overkill for small, completely static lists that will never change. If you're using SwiftUI, the @FetchRequest property wrapper provides similar functionality with a more modern, declarative API.
ONE CANONICAL EXAMPLE A to-do list app. The main screen is a UITableView showing tasks from Core Data. When the user adds a new task, the FRC's delegate is notified of an insertion. Your code then calls tableView.insertRows(...) with the provided index path, and the new task animates smoothly into the list. The same happens for deletions and updates.
Read the original → developer.apple.com
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.