【问题标题】:NSPredicate interpreting a keyPath instead of a propertyNSPredicate 解释 keyPath 而不是属性
【发布时间】:2015-05-06 11:39:44
【问题描述】:

我有一个RecipesCore Data 数据库。每个Recipe 都有一个ingredients 关系(多对多),所以我的XYZRecipe 对象有一个ingredients 属性,它指向NSSetXYZIngredients

我想要一个NSPredicate 来选择所有具有超过 5 个ingredientsRecipes 并尝试了这个:

NSPredicate *p = [NSPredicate predicateWithFormat:@"ingredients.count > 5"];

这失败了,并抱怨XYZIngredient 类不符合count 的键值。

显然"ingredients.count" 被解释为keyPath,而不是返回每个配方的ingredients 属性。

有没有办法解决这个问题?

【问题讨论】:

标签: objective-c core-data nspredicate


【解决方案1】:

应该可以在 KVC 端和 Core Data 端解决这个问题:

KVC:

@"ingredients.@count > 5"

应该传递成分计数作为关键路径的结果。

核心数据:

@"ingredients[SIZE] > 5" 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-16
    • 2010-12-15
    • 2013-07-15
    • 2019-03-01
    相关资源
    最近更新 更多