繁体   English   中英

无法将类型'(_) - > Bool'的值转换为预期的参数类型'NSPredicate'

[英]Cannot convert value of type '(_) -> Bool' to expected argument type 'NSPredicate'

我正在使用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
    })

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

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

这是上述问题的解决方案

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

把文字as! NSDictionary as! NSDictionary

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM