如果我["Hello","Bye","Halo"]要搜索的主数组是,"lo"它将只将该数组过滤为["Hello", "Halo"]。
["Hello","Bye","Halo"]
"lo"
["Hello", "Halo"]
这是我尝试过的:
let matchingTerms = filter(catalogNames) { $0.rangeOfString(self.txtField.text!, options: .CaseInsensitiveSearch) != nil }
它抛出
Type of expression is ambiguous without more context
有什么建议?
使用contains来代替:
contains
let arr = ["Hello","Bye","Halo"] let filtered = arr.filter { $0.contains("lo") } print(filtered)
输出量
[“ Hello”,“ Halo”]
感谢@ user3441734指出,功能仅在您使用时才可用 import Foundation
import Foundation