1
votes

I'm getting into Core Data and have started making "Classes" out of entities. Do I use these classes based off of entities as regular classes with methods etc?

Normally if I was using SQL directly I would have classes for each of my database objects (Tables) that store the working data and perform their functions.

Is this the same with Core Data - do I use the entity-based classes (subclasses of NSManagedObject).

So I might have these entities: Business -> Departments -> Employees

To comply with Core Data - do I make one class for each of these subclassing NSManagedObject and then add methods to it accordingly (like I would an NSObject class)?

2

2 Answers

2
votes

Yes, you usually use the Core Data generated classes. You usually don't add methods to those classes, instead you should put them into a Category. This is because if you change an entity, you need to regenerate the class which will erase any methods that you added.

0
votes

Yes(ish). They are your model classes. You aren't creating them 'out of' entities, they are the code representation of your entities.

You should have one class per entity, but you shouldn't create them yourself. You should get Xcode to create the classes. Or, better yet, use mogenerator.