无法转换类型的值'(_) - >布尔'预期的论证类型' NSPredicate'

时间:2017-01-07 10:47:25

标签: ios

我正在使用Swift 3中的filter()方法,但遇到问题,我的代码就是....

filtered = arrayTag.filter(using: { (text) -> Bool in
        //Access the title and sectors
        let tmpTitle = text["tag_name"] as! String
        let tmpSector = text["tag_id"] as! String

        //Create a range for both
        let range1 = tmpTitle.range(of: searchText, options: NSString.CompareOptions.caseInsensitive)
        let range2 = tmpSector.range(of: searchText, options: NSString.CompareOptions.caseInsensitive)
        print("search result \(text)")

        //Return true if either match
        return range1 != nil || range2 != nil
    })

2 个答案:

答案 0 :(得分:0)

filter(using:)对象的方法NSMutableArrayNSPredicate作为参数。要使用filter功能,请更改以下代码:

filtered = arrayTag.filter { text in
    //your code
}

答案 1 :(得分:0)

以上是上述问题的解决方案

let tmpTitle = (text as! NSDictionary)["tag_name"] as? String

演员文字as! NSDictionary