【问题标题】:Core Data Predicate "Unable to parse the format string"核心数据谓词“无法解析格式字符串”
【发布时间】:2014-05-27 16:06:41
【问题描述】:

我正在尝试获取一组与其他对象具有特定关系的NSManagedObjects

所以我有 4 个托管对象:UserPickGameGroupUser。 UserPick 分别与GameGroupUser 具有一对一的关系。我需要找到所有具有特定GameGroupUserUserPicks,但我似乎无法正确构建谓词:

我试过了:

[NSPredicate predicateWithFormat:@"%K = %@, %K = %@, %K = %@",
UserPickRelationships.game, game,
UserPickRelationships.group, group,
UserPickRelationships.user, user]

和:

[NSPredicate predicateWithFormat:@"%K = %@, %K = %@, %K = %@",
UserPickRelationships.game, game.objectID,
UserPickRelationships.group, group.objectID,
UserPickRelationships.user, user.objectID]

终于:

[NSPredicate predicateWithFormat:@"%K.%K = %@, %K.%K = %@, %K.%K = %@",
UserPickRelationships.game, @"objectID", game.objectID,
UserPickRelationships.group, @"objectID", group.objectID,
UserPickRelationships.user, @"objectID", user.objectID]

我已经尝试在所有可能的组合中使用%@%K。我得到的只是:NSPredicate cannot parse format string。我怎样才能做到这一点?

【问题讨论】:

    标签: objective-c core-data nspredicate format-string


    【解决方案1】:

    您可能希望将条件与“AND”结合起来:

    [NSPredicate predicateWithFormat:@"%K = %@ AND %K = %@ AND %K = %@",
    UserPickRelationships.game, game,
    UserPickRelationships.group, group,
    UserPickRelationships.user, user]
    

    (假设UserPickRelationships.game 计算结果为字符串"game")。

    【讨论】:

    • 天哪,这是一个愚蠢的错误。谢谢你。我想我现在再去喝杯咖啡……
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-07
    • 1970-01-01
    • 2013-08-05
    • 2015-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多