Szu
Szu

Reputation: 2252

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];
}

Upvotes: 1

Views: 1022

Answers (1)

Szu
Szu

Reputation: 2252

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];
}

Upvotes: 1

Related Questions