Question

I have this Model situation -

  1. Group entity is in One on One relationship with Event entity called latestEvent.
  2. Event entity has a child entity called 'WeddingEvent' which is one of many child events.
  3. WeddingEvent is the only one who has a property called present
  4. I am trying to filter Group to not be fetched if the latestEvent is of kind 'WeddingEvent'.

Since I can not fetch by className or by entityName I tried :

NSPredicate *LatestEventValidity = [NSPredicate predicateWithFormat:@"latestEvent.present != nil"];

AND

 NSPredicate *LatestEventValidity = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary * bindings) {
        OOVGroup *group = evaluatedObject;
        return [group.latestEvent respondsToSelector:@selector(setPresent:)];
    }];

But they al failed.

Any help here ?

Was it helpful?

Solution

The first predicate does not work because not all Event objects respond to the "present" selector. The second predicate does not work because you cannot use block-based (or any Objective-C based) predicates in a Core Data fetch request.

The only solution is probably to add a (string or integer) "type" attribute to your "Event" entity, so that you can filter with a predicate like "lastEvent.type != 'Wedding'".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top