Search code examples
iphoneioscore-dataios6

Subclass UITableViewController or use a Store (MVCS)?


I'm working on my first iOS app and I'm trying to figure out the best/recommended way to manipulate my model when using CoreData.

I've seen people subclass UITableViewController (copying code from NSFetchedResultsController's documentation page, see Standford iOS course) and then subclassing this last class on their TableViewControllers.

I've alson seen people using the MVCS pattern in which the store is responsible to handle most or all of the model.

The iOS version of my app will use quite a few TableViewControllers, but in the iPad version I will stay away from them as much as I can.

What are the best practices when working with CoreData? I know this question might sound subjective, but maybe giving the pros and cons of these two (or any other) patters would help me a lot, even if they might seem obvious to many of you.


Solution

  • I've used Core Data a lot for a number of apps.

    I'd recommend using Magical Record to make everything easier http://cocoapods.org/?q=magical%20record (Cocoapods makes it very easy to add frameworks too).

    Have a look at the github page of magical record to see some usage examples.

    With TableViews use an NSFetchedResultsController like in this tutorial http://www.raywenderlich.com/999/core-data-tutorial-how-to-use-nsfetchedresultscontroller . Except when creating the NSFetchedResultsController use the magical record function [Blah fetchAll...]

    Now with your table view whenever you update the data on the table it will automagically update the view.