Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Data List Entity Names

using Core Data, how would I list (i.e. return an NSArray of NSStrings) all the entity types that I have in my model?

such as Customer, Invoice, etc...

like image 783
Jason Cragun Avatar asked May 13 '11 20:05

Jason Cragun


People also ask

What is an entity in Core Data?

An entity describes an object, including its name, attributes, and relationships. Create an entity for each of your app's objects.

What is abstract entity in Core Data?

Specify that an entity is abstract if you will not create any instances of that entity. You typically make an entity abstract if you have a number of entities that all represent specializations of (inherit from) a common entity that should not itself be instantiated.

How do I get NSManagedObject?

Still inside the Core Data editor, go to the Editor menu and choose Create NSManagedObject Subclass. Make sure your data model is selected then click Next. Make sure the Commit entity is checked then click Next again.


1 Answers

You can get the names from the model's entity descriptions:

NSArray *entityNames = [[myManagedObjectModel entities] valueForKey:@"name"];

or perhaps just:

NSArray *entityNames = myManagedObjectModel.entities.name;
like image 155
Caleb Avatar answered Sep 29 '22 23:09

Caleb