Вопрос

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 ?

Это было полезно?

Решение

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'".

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top