nspredicate取代不起作用

时间:2014-08-18 04:43:00

标签: ios nspredicate

您好我正在尝试使用替换但我收到错误

NSPredicate *pred = [NSPredicate predicateWithFormat:
                     @"city $C $A or "
                     " state $C $A or "
                     " name $C $A "]; // <-- crashes here
pred = [pred predicateWithSubstitutionVariables:@{@"A":self.searchBar.text,
                                                  @"C":@"contains[c]"}];

这是关于主题的苹果文档的示例代码

NSPredicate *predicate = [NSPredicate
    predicateWithFormat:@"date = $DATE"];
predicate = [predicate predicateWithSubstitutionVariables:
    [NSDictionary dictionaryWithObject:[NSNull null] forKey:@"DATE"]];

我不确定我做错了什么。我简单地希望所有$ A占位符都被替换为相同的字符串;在这种情况下,它是self.searchBar.text

谁能告诉我为什么这不起作用?

1 个答案:

答案 0 :(得分:0)

显然你只能在变量上使用替换。