LHS和RHS都是关键路径

时间:2014-04-18 21:15:59

标签: core-data ios7 nsfetchedresultscontroller

尝试查找guestCards与所有搜索查询匹配的有效prospectiveTenant。可能性为firstNamelastNamephoneNumber

prospectiveTenantsguestCard上的多对多。

此代码:

NSString *predicateString = [NSString stringWithFormat: @"active=1"];
if (self.searchHeader.firstNameTextField.text.length > 0) {
    predicateString = [predicateString stringByAppendingFormat:@" AND (ANY prospectiveTenants.firstName CONTAINS[cd] %@)", self.searchHeader.firstNameTextField.text];
}
if (self.searchHeader.lastNameTextField.text.length > 0)
{
    predicateString = [predicateString stringByAppendingFormat:@" AND (ANY prospectiveTenants.lastName CONTAINS[cd] %@)", self.searchHeader.lastNameTextField.text];
}
if (self.searchHeader.phoneNumberTextField.text.length > 0)
{
    predicateString = [predicateString stringByAppendingFormat:@" AND (ANY prospectiveTenants.phone CONTAINS[cd] %@)", self.searchHeader.phoneNumberTextField.text];
}

NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateString];
[self.fetchedResultsController.fetchRequest setPredicate:predicate];

产生此错误

'unimplemented SQL generation for predicate : (ANY prospectiveTenants.lastName CONTAINS[cd] S) (LHS and RHS both keypaths)'

2 个答案:

答案 0 :(得分:7)

尔加。

所以看起来predicateWithFormat做了特别的工作来确保在字符串周围插入引号。应该是显而易见的。

答案 1 :(得分:0)

为了能够使用NSPredicate init所做的工作,尝试将格式字符串和要放在字符串中的值构建为两个变量,然后在创建{{1 }}

这样做的好处是可以处理NSPredicate可能要做的任何其他特殊工作。

在Swift中重写,这将成为:

NSPredicate