当我使用NSPredicate格式从数组中搜索值时,我遇到了此问题但我无法修复,请帮我解决问题。
在这里,我发布了我正在尝试的代码..
var getCounty = NSArray()
var arrCountyFilterData = NSArray()
let predicate: NSPredicate = NSPredicate(format: "a:CountyName contains[c] %@",text);
let predicateSecond: NSPredicate = NSPredicate(format: "text contains[c] %@",text)
let predicateCompound = NSCompoundPredicate.init(type: .or, subpredicates: [predicate,predicateSecond])
arrCountyFilterData = self.getCounty.filter { predicateCompound.evaluate(with: $0) } as NSArray;
showSearchCountyResults = true
getCounty数组是:
getCounty is: (
{
"a:CaDId" = {
text = 3;
};
"a:CountyName" = {
text = Anderson;
};
},
{
"a:CaDId" = {
text = 241;
};
"a:CountyName" = {
text = Andrews;
};
},
{
"a:CaDId" = {
text = 4;
};
"a:CountyName" = {
text = Angelina;
};
},
{
"a:CaDId" = {
text = 5;
};
"a:CountyName" = {
text = Aransas;
};
})