我正在使用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
})
答案 0 :(得分:0)
filter(using:)
对象的方法NSMutableArray
将NSPredicate
作为参数。要使用filter
功能,请更改以下代码:
filtered = arrayTag.filter { text in
//your code
}
答案 1 :(得分:0)
以上是上述问题的解决方案
let tmpTitle = (text as! NSDictionary)["tag_name"] as? String
演员文字as! NSDictionary
。