原因:'无法解析格式字符串" a:CountyName =%@"'

时间:2017-12-08 08:02:21

标签: ios swift nspredicate

当我使用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;
    };
})

0 个答案:

没有答案