I've just gotten into making applications with CoreData, but I'm familiar with MVC concepts because I used to do a lot of work in web development using (and developing) MVC frameworks.
From what I gather, CoreData automatically generates classes that inherit from NSManagedObject. The objects are created by a fetch request to the context or by inserting a new one into the context. In the apps I've seen, the objects are empty aside from properties that correspond to their attributes in the database, essentially making them objects that mimic a row in the entity's table.
It makes sense that those automatically generated classes and CoreData itself make up the applications model. In the apps I've made traditionally, there is instead a Model
class that is in charge of handling all of the data. This is often a Singleton class, and each controller that needs the model can simply use self.model = [Model sharedInstance];
. For bigger apps, there may be multiple models instead of one gigantic one. You get the picture. I guess my first question is: am I right? CoreData and it's associated NSManagedObject's make up the entire model for an application?
I would guess that is wrong, because an application may need other functionality that deals with data that does not have an assigned CoreData object. For example: what if a CoreData application needs to populate a table view with data that is retrieved through an HTTP request from foo.com/test (let's say it is JSON data). This data does not need to be stored in CoreData, but at the same time, I don't think retrieving and parsing the data is a job for a controller. Should there be an object, FooDataManager
(or something like that) that handles the HTTP requests to manage data from foo.com (it could extend AFHTTPClient). And then controllers that deal with foo.com have a property for fooDataManager
, which acts as a model for that controller? And then controllers will call [self.fooDataManager retrieveAndParseData];
?
I want to verify this information before I start developing CoreData apps so that I do it correctly from the start. In web development, I'm used to having one model for each controller, but it seems like on iOS, there can be many models that all do their own thing, many controllers who use those models, and all of those models are in addition to CoreData and the NSManagedObjects.