0
votes

In Core data, I have three types of entities. Entity A, Entity B, Entity C

Entity C to entity A is a one to many relationship. Entity C to entity B is also a one to many relationship.

In another word, Both A and B has an inRecord field which points to a single instance of Entity C.

I have the following code

    NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"EntityA"];

    request.predicate = [NSPredicate predicateWithFormat:@"inRecord.title = %@", title];
    NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"date" ascending:YES];
    request.sortDescriptors = [NSArray arrayWithObject:sortDescriptor];

    NSError *error = nil;
    NSArray *arrayOfEntity = [context executeFetchRequest:request error:&error];

Now if I check the class of arrayOfEntity[0], it will say it is of class EntityA. However, with the exact same code, if I replaced EntityA by EntityB above, if I check the class of arrayOfEntity[0], it does not say EntityA, instead, it says it is class NSManagedObject.

Why is that?

1
Have you checked in the Core Data Model inspector if the "Class" of "EntityB" is set to "EntityB"?Martin R
Did you set the entity class in the entity properties?serrrgi
Bingo you guys are right. Thanks man.huggie

1 Answers

1
votes

You have to set the "Class" of the entity in the Core Data Model inspector to your managed object subclass.

(The class is set automatically if you create a custom class for the entity with "Editor -> Create Managed Object Subclass ..." from the Xcode menu.)