Reputation: 1102
Core Data isn't trivial for manipulate models.
Before I use Core Data, I use a simple sqlite3 database and I manipulate object which I alloc and modify how I want.
But with Core Data, if I modify an entity or delete the context in which I create it ... It's really dangerous for the coordination of my application.
My question is simple, how do you do for safely manipulation of the entities ?
Do you use entity just for save, delete, update and fetch persistent store or you write function in entities and use it like a real object ?
For example, I have a map with many overlays, and each overlay has player. I created four objects : MyAppPlayer: Models, Player: Entity, MyAppOverlay: Models, Overlay:Entity. MyAppPlayer load and store entities, is it a good practice ? if no, how do you do ?
Upvotes: 0
Views: 224
Reputation: 80273
Core Data is an object graph, not a database.
You should think of Core Data as simply the backbone for the persistence of your objects. The persistent store contains the data, your custom classes the functionality.
Yes, do add custom functionality to your class files. That's what they are here for.
However, be sure you understand the concepts. You do not "delete a context". It is simply a convenient "scratchpad" for your data manipulations. You pass the context on to your controllers so they can access and manipulate the data.
In your case, there is no need to distinguish between "Model" and "Entity". The entity is indeed part of the model (as defined in our NSManagedObjectModel). It's quite straight forward: create map overlays that rely on your custom entities as their data source.
Upvotes: 2
Reputation: 9414
Think of an entity as a table and attributes as columns. Relationships (One to many, many to many, etc) are also very similar since CoreData just uses SQLite as it's persistent store. Entities can have multiple attributes and relationships. If you are familiar with SQL then this should all make sense. You can open up the SQLite store file and see how CoreData organizes things to clear up any confusion.
Upvotes: 1