1

I am attempting to make core data fetches with an NSExpression. All fetch request will access the object 'Organisation' so that will remain constant. However I need to access relationships from this object and that is where I am having issues.

So for example I can do the following if I want to access the south property on population object: organisation.population.south

However if I try to create an NSExpression as follows:

NSExpressionDescription *aveExDescr = [[NSExpressionDescription alloc] init];
    [aveExDescr setName:@"myAverage"];
    NSExpression *expression = [NSExpression expressionForKeyPath:@"population.south"];
    [aveExDescr setExpression:[NSExpression expressionForFunction:@"average:"
                                                    arguments:[NSArray arrayWithObject:
                                                               expression]]];

it causes the following exception: request for aggregate operation on a toOne-only keypath): population.south

I can't work out why this doesn't work. If I request the 'Population' object directly and use:

NSExpression *expression = [NSExpression expressionForKeyPath:@"south"];

it works fine.

If you require further information or clarification then let me know. Any help would be much appreciated.

pls
  • 1,522
  • 2
  • 21
  • 41
  • would love to know the answer to this too. I'd like to get the max value of a field in all the to-one related objects. – malhal Aug 30 '15 at 23:20

0 Answers0