以下是代码:
private func filter(searchText: String) -> [MICountry] {
filteredList.removeAll()
sections.forEach { (section) -> () in
section.countries.forEach({ (country) -> () in
let result = country.name.compare(searchText, options: [.CaseInsensitiveSearch, .DiacriticInsensitiveSearch], range: searchText.startIndex ..< searchText.endIndex)
if (result == .OrderedSame) {
filteredList.append(country)
}
})
}
return filteredList
}
我的国家/地区类别如下:
class MICountry: NSObject {
let name: String
var section: Int?
init(name: String) {
self.name = name
}
}
struct MISection {
var countries: [MICountry] = []
mutating func addCountry(country: MICountry) {
countries.append(country)
}
}