您可以從「謂詞模板」創建謂詞。然而,$1
不在謂詞模板有效 變量和
[NSPredicate predicateWithFormat:@"[email protected] == 50"]
實際上導致運行時異常。但是,下面的作品,並應表現出的理念:
NSPredicate *p1 = [NSPredicate predicateWithFormat:@"[email protected] == 50"] ;
NSLog(@"%@", p1);
// [email protected] == 50
// Substitute $foo by self:
NSPredicate *p2 = [p1 predicateWithSubstitutionVariables:@{@"foo": [NSExpression expressionForEvaluatedObject]}];
NSLog(@"%@", p2);
// [email protected] == 50
// Substitute $foo by "bar":
NSPredicate *p3 = [p1 predicateWithSubstitutionVariables:@{@"foo": [NSExpression expressionForKeyPath:@"bar"]}];
NSLog(@"%@", p3);
// [email protected] == 50
欲瞭解更多信息,請參見「謂語編程指南」中"Creating Predicates Using Predicate Templates" 。
我愛你@馬丁= 8-°<3 _/\\ _ – Colas
@Colas:接受答案怎麼樣? –
是的你是對的,我在等着看有沒有人會帶更好的東西......但是怎麼可能呢? – Colas