Reputation: 24912
I have a Core Data
database of Recipes
. Each Recipe
has an ingredients
relationship (many to many), so my XYZRecipe
object has a ingredients
property that points to an NSSet
of XYZIngredients
.
I want an NSPredicate
to select all the Recipes
that have more than 5 ingredients
and tried this:
NSPredicate *p = [NSPredicate predicateWithFormat:@"ingredients.count > 5"];
This fails, and complains that the class XYZIngredient
is not key value compliant for count
.
Clearly "ingredients.count"
is being interpreted as a keyPath
instead of returning the ingredients
property of each recipe.
Is there a way around this?
Upvotes: 0
Views: 136
Reputation: 16660
It should be possible to solve that problem on KVC side and on Core Data side:
KVC:
@"ingredients.@count > 5"
Should deliver the count of ingredients as the result of the key path.
Core Data:
@"ingredients[SIZE] > 5"
Upvotes: 2