代码之家  ›  专栏  ›  技术社区  ›  Barry Wark

为多个键自动生成谓词行模板?

  •  3
  • Barry Wark  · 技术社区  · 17 年前

    在我的核心数据管理对象模型中,我有一个实体Foo,它与实体Baz具有对多关系(与对多相反),名为Baz。Baz有一个名为“tag”的字符串属性。当我使用 [NSPredicateRowEditorTemplate templatesWithAttributeKeyPaths:[NSArray arrayWithObject:@"baz.tag"] inEntityDescription:FooDescription] 要为NSPredicateEditor创建行编辑器,结果包含(如预期的)行模板,如

    当我从弹出窗口中选择“Contains”时,带有谓词的查询将按预期工作。如果我选择任何其他弹出窗口(例如“is”),我会得到以下错误:“to many key not allowed here”。我能用吗 [NSPredicateRowEditorTemplate templatesWithAttributeKeyPaths:inEntityDescription:] 还是必须手动构建行编辑器?

    1 回复  |  直到 17 年前
        1
  •  4
  •   Barry Wark    17 年前

    它看起来像是自动生成的模板(使用 [NSPredicateRowEditorTemplate templatesWithAttributeKeyPaths:inEntityDescription:] )无法生成正确的运算符。解决方案是使用手动创建模板 [NSPredicateEditorRowTemplate initWithLeftExpressions:rightExpressionAttributeType:modifier:operators:options:] . 对于给定的示例:

    id template = [[NSPredicateEditorRowTemplate initWithLeftExpressions:[NSArray arrayWithObject:[NSExpression expressionForKeyPath:@"baz.tag"]] rightExpressionAttributeType:NSStringAttributeType modifier:NSAnyPredicateModifier operators:keywordOperators options:0];