简体   繁体   中英

Get all entities from Model.xcdatamodeld

In my project I am using MagicalRecord framework (implementation of active record pattern for Core Data on iOS). How can I retrieve all existing ENTITIES from my .xcdatamodeld file? I have to iterate though all entities (classes that inherit from managed object in my project) to truncate stored data.

I have only default configuration set in my model file. So for the following data model:

My code that show how it should look like:

NSArray *myEntities = // Retrive my entities.
foreach (Class *c in myEntities) {
    [c MR_truncateAll];
}

Okey I have found the solution over here . The answer is pretty simple:

NSArray *allEntities = [[NSManagedObjectModel MR_defaultManagedObjectModel] entities];
for (NSManagedObject *mo in allEntities) {
    [[mo class] MR_truncateAll];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM