我正在使用Swift 3中的filter()方法,但遇到问题,我的代码是....无法将类型'(_) - > Bool'的值转换为期望的参数类型'NSPredicate'
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
})
'arrayTag'是什么类型? – dfri
var arrayTag:NSMutableArray = NSMutableArray() –
'NSMutableArray'不响应'filter'。使用本地Swift'Array'。 – vadian