I think this is a common scenario.
I’m defining class models of my app, I will use Core Data for caching so I would like to take advantage of the NSManagedObject generated subclass to “reuse” it as a model to pass to different classes.
Is that advisable?
Let’s say I get some data from the network I want to build an object model with same instance variables as the Core Data model generated, use it when needed and maybe cache it on the DB.
What is the common approach there?
Can I use a category on Core Data model?
Core Data subclass? Encapsulation? New class ?
Thanks for any tips on that.
I think this is a common scenario. I’m defining class models of my app,
Share
Core Data is not, at its heart, a database, but rather an object graph manager.
In many scenarios, it is a very good idea to handle your objects with Core Data, and you can use a fast in-memory store.
In a way, I think that by attempting NOT to use Core Data to handle your objects, you are destined to re-implement a lot of its functionality. Just use it.
You say that you are downloading a JSON that represents a given item; and you’re using this item in your views, and then persisting it in a database. Core Data excels at this; take advantage of its full set of features instead of trying to avoid it.
(And, again, using mogenerator will be very helpful, although it is certainly not required).
Matt Gallagher has a nice blog article about the differences between Core Data and a database – I suggest that you read it, it’s valuable information.
Cocoa With Love: The differences between Core Data and a Database