I have an NSPredicate that includes several aggregate filters that throw an exception.
I have the following kernel data model:

I want to select those ApparelItems for which any of the colours has rgb 13576743 and for which all picks have pickTime earlier than the specified NSDate .
My code for creating a predicate:
let request = NSFetchRequest(entityName: "ApparelItem") var predicates = [NSPredicate]() predicates.append(NSPredicate(format: "ANY colours.rgb = 13576743")) // find the NSDate representing midnight x days ago let cal = NSCalendar.currentCalendar() if let xDaysAgo = cal.dateByAddingUnit(.Day, value: -2, toDate: NSDate(), options: []) { let midnightXDaysAgo = cal.startOfDayForDate(xDaysAgo) predicates.append(NSPredicate(format: "(ALL picks.pickTime < %@)", midnightXDaysAgo)) } request.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: predicates) let searchData = try? objectContext.executeFetchRequest(request)
I get the following exception:
Exception name=NSInvalidArgumentException, reason=Unsupported predicate (ANY colours.rgb == 13576743) AND ALL picks.pickTime < CAST(479347200.000000, "NSDate")
I tried:
Each individual predicate works fine. Those. ANY colours.rgb = ... works, ALL picks.pickTime < ... also works. They simply do not work when combined into the same query.
Combining the two uses in a single query associated with AND , instead of using NSCompoundPredicate . The result is the same.
Is it possible that master data simply does not support filtering relationships of more than one? That would seem odd. In which case should I do it higher?
source share