How to get list of existing entities(tables) in core data

你。 提交于 2019-12-06 22:58:36

问题


How to get list of existing entities(tables) for a particular schema(Managed object model) in core data. I just started implementing core data concept and stuck with these points, please help

something like : SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'dbName';

Thanks


回答1:


You should read through Apple's Core Data Programming Guide. To get the entities for a particular NSManagedObjectModel, you would use one of the following (this assumes you have an NSManagedObjectModel named objectModel):

NSArray *myEntities = [objectModel entities];
// Array of all entities in the model

or

NSDictionary *myEntities = [objectModel entitiesByName];
// Dictionary of entities in the model, with the entity names as keys

You can read more in the NSManagedObjectModel Class Reference.

It appears you're coming from a SQL background (as I was). There are a number of concepts in Core Data that are different - sometimes for the better, once you understand them, sometimes requiring more work than a simple SQL statement you may be used to. I think it's important to approach Core Data without SQL "baggage" and treat it as if you're learning how to use a database for the first time - this will help avoid frustration.



来源:https://stackoverflow.com/questions/15652745/how-to-get-list-of-existing-entitiestables-in-core-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!