为多对键自动生成谓词行模板?
-
03-07-2019 - |
题
在我的核心数据管理对象模型中,我有一个实体Foo,它与实体Baz之间存在多对多关系(与多对数关系),命名为baz。 Baz有一个名为“tag”的字符串属性。当我使用 [NSPredicateRowEditorTemplate templatesWithAttributeKeyPaths:[NSArray arrayWithObject:@" baz.tag"] inEntityDescription:FooDescription]
为NSPredicateEditor创建行编辑器时,结果包含(如预期的那样)行模板,如
[Popup:baz.tag] [弹出:包含|是|不是| ...] [TextField]
当我选择“包含”时从弹出窗口,带谓词的查询按预期工作。如果我选择任何其他弹出窗口(例如“是”),我会收到以下错误:“此处不允许使用多对键”。我可以使用 [NSPredicateRowEditorTemplate templatesWithAttributeKeyPaths:inEntityDescription:]
还是我必须手动构建行编辑器?
解决方案
看起来自动生成的模板(使用 [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];