2009-09-12 51 views
2

我已經看到,在關係查詢中工作的每個謂詞都包含開頭的單詞ANY或ALL(即:ANY tags.name LIKE [c]「car」),事實是,如果我刪除它(即:tags.name LIKE [c]「car」),結果是錯誤的或者我得到這樣的消息:無法在對象上執行正則表達式匹配。NSPredicateEditor和關係

因爲我使用的是NSPredicateEditor,它們不是任何或所有啓動我的查詢,所以它總是失敗。 返回的謂詞總是像第二個例子(沒有任何或全部)。

我是否必須繼承NSPredicateRowTemplateEditor,才能將自己的ANY或ALL添加到我的謂詞中,還是另一種方式?

與日期相同......我的日期以這種格式保存:YYYY-MM-DD HH:mm:ss,但NSPredicateEditor使用DD/MM/YYYY,所以每次我嘗試日期比較時,這是行不通的。我是否還必須繼承RowEditor以更改日期格式?

謝謝。

+0

在這裏找到答案: http://stackoverflow.com/questions/210735/automatically-generated-predicate-row-templates-for-to-many-key – gertiMN 2012-02-18 17:42:07

回答

0

在這裏你去:

class RowTemplateRelationshipAny: NSPredicateEditorRowTemplate { 



    override func predicate(withSubpredicates subpredicates: [NSPredicate]?) -> NSPredicate{ 

     let predicate: NSComparisonPredicate = super.predicate(withSubpredicates: subpredicates) as! NSComparisonPredicate 

     let newPredicate = NSComparisonPredicate(leftExpression: predicate.leftExpression, rightExpression: predicate.rightExpression, modifier: .any, type: predicate.predicateOperatorType, options: predicate.options) 

     return newPredicate 
    } 

} 

class RowTemplateRelationshipAll: NSPredicateEditorRowTemplate { 


    override func predicate(withSubpredicates subpredicates: [NSPredicate]?) -> NSPredicate{ 

     let predicate: NSComparisonPredicate = super.predicate(withSubpredicates: subpredicates) as! NSComparisonPredicate 

     let newPredicate = NSComparisonPredicate(leftExpression: predicate.leftExpression, rightExpression: predicate.rightExpression, modifier: .all, type: predicate.predicateOperatorType, options: predicate.options) 

     return newPredicate 
    } 

} 

只要改變在IB你行的模板類RowTemplateRelationshipAny或RowTemplateRelationshipAll。