Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use NSFetchedResultsController?

Tags:

Core data provides the method "executeFetchRequest" in NSManagedObjectContext class, which we can use to fetch data from tables and use it whatever the way need to.

Now there is another way by using NSFetchedResultsController and providing it to UITableView to fetch and data from tables.

My questions are now:

  • Which way is faster?, I mean performance wise, which one is the best?

  • Is NSFetchedResultsController is only used with UITableViews?

  • What are the Pros and Cons of the NSFetchedResultsController.

  • And last thing, "Why we use NSFetchedResultsController", what thing makes it better than any other way.

like image 370
Ansari Avatar asked Sep 17 '10 10:09

Ansari


People also ask

What is NSFetchedResultsController?

A controller that you use to manage the results of a Core Data fetch request and to display data to the user.

What is Nsfetchrequest in Swift?

A description of search criteria used to retrieve data from a persistent store.


1 Answers

And last thing, "Why we use NSFetchedResultsController", what thing makes it better than any other way.

The FRC class is designed to automatically handle all the overhead associated with providing complex and dynamic data for tables.

If all you have is a simple, one section table whose data never changes, then an FRC gives you no advantage. You just do one fetch and you are done. However, if the data is being changed either in UI (user rearranges, deletes or adds) or by code (e.g data is being updated from a server) the FRC provides the mechanisms for handling all that constant change and making sure the table accurately reflects those changes.

Which way is faster?, I mean performance wise, which one is the best?

There is no major performance difference in using either a fetch or FRC because they both use the same fetch mechanism to get data from the persistent store. If you have complex dynamic data then it is faster to use the FRC than to duplicate its functionality by hand.

What are the Pros and Cons of the NSFetchedResultsController.

See above.

Is NSFetchedResultsController is only used with UITableViews?

Yes, its really is only useful with tables.

like image 56
TechZen Avatar answered Oct 13 '22 20:10

TechZen