Here is an example of how you set up your search query for only weeks when the sum of the days is more than 100.
NSManagedObjectContext *context = ...;
NSManagedObjectModel *model = ...;
NSFetchRequest *fr = [[NSFetchRequest alloc] init];
fr.entity = [model.entitiesByName objectForKey:@"Week"];
fr.predicate = [NSPredicate predicateWithFormat:@"days.@sum.duration > 100"];
NSError *error = nil;
NSArray *results = [context executeFetchRequest:fr error:&error];
if (error) {
NSLog(@"ERROR: %@", error);
}
NSLog(@"Results: %@", results);
In fact, you can implement the computed property in the same way, just add it to a subclass of NSManagedObject that supports the Week object:
- (NSNumber *) duration {
return [self valueForKeyPath:@"days.@sum.duration"];
}
source
share