复合谓词

时间:2015-04-29 16:57:55

标签: ios swift core-data nspredicate

我试图通过UITableView(搜索和显示控制器)对核心数据进行复合搜索:

let firstNamePredicate = NSPredicate(format: "fname CONTAINS[c] %@", searchText)

let lastNamePredicate = NSPredicate(format: "lname CONTAINS[c] %@", searchText)

let firstAndLastNamePredicate = NSPredicate(format: "fname contains[c] %@ OR lname contains[c] %@", searchText, searchText)

let companyPredicate = NSPredicate(format: "company CONTAINS[c] %@", searchText)

let predicate = NSCompoundPredicate(type: NSCompoundPredicateType.OrPredicateType, subpredicates: [firstNamePredicate, lastNamePredicate, companyPredicate, firstAndLastNamePredicate])

fetchRequest.predicate = predicate

除了名字和姓氏谓词之外,所有谓词都有效。我可以输入一个名字并完美地获得结果,但是一旦我输入并键入姓氏,我就不会得到任何结果。知道我的名字和姓氏谓词有什么问题吗?

0 个答案:

没有答案