Search code examples
iosswiftcore-datansfetchedresultscontrollernsfetchrequest

Swift: Difference between NSFetchRequest and NSFetchResultsController?


I have a hard time to understand the difference between the NSFetchRequest and the NSFetchResultsController. I also don't know in which situation I would choose which one of them.

I would be really happy, if someone could explain it in simple terms.


Solution

  • NSFetchRequest is a simple static description of the set of NSManagedObjects you would like to grab from your NSManagedObjectContext.

    NSFetchResultsController helps manage the objects fetched for use in an (NS/UI) TableView/CollectionView. The set of objects returned by an NSFetchRequest can change as objects are edited/inserted/deleted in your NSManagedObjectContext. NSFetchResultsController will help you track these changes.

    NSFetchResultsController is configured with an NSFetchRequest.