2008-10-17 52 views
2

在我的核心數據管理對象模型中,我有一個實體Foo,它與實體Baz命名爲baz的多對多關係(具有對多個逆)。 Baz有一個名爲「tag」的字符串屬性。當我使用[NSPredicateRowEditorTemplate templatesWithAttributeKeyPaths:[NSArray arrayWithObject:@"baz.tag"] inEntityDescription:FooDescription]爲NSPredicateEditor創建行編輯器時,結果包含(如預期的)行模板,如爲多對多關鍵字自動生成謂詞行模板?

[Popup:baz.tag] [Popup:Contains | is | is not | ...] TextField]

當我從彈出窗口中選擇「Contains」時,帶謂詞的查詢按預期工作。如果我選擇其他彈出窗口(例如「is」),則會出現以下錯誤:「此處不允許使用多對多密鑰」。我可以使用[NSPredicateRowEditorTemplate templatesWithAttributeKeyPaths:inEntityDescription:]還是必須手動構建行編輯器?

回答

3

它看起來像自動生成的模板(使用[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];