Reputation: 578
I have created a search bar in Xcode using Swift 3. I get the data through an api. However, while I search the cursor goes away. Not only that but before I put a delay in it I could only type one letter. I'm not sure if it was my code, the async or what.
So I found this article (http://shrikar.com/swift-ios-tutorial-uisearchbar-and-uisearchbardelegate/)
The problem I'm having is this portion in Swift 3:
func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
filtered = data.filter({ (text) -> Bool in
let tmp: NSString = text
let range = tmp.rangeOfString(searchText, options: NSStringCompareOptions.CaseInsensitiveSearch)
return range.location != NSNotFound
})
if(filtered.count == 0){
searchActive = false;
} else {
searchActive = true;
}
self.tableView.reloadData()
}
So I used the documentation and found:
static var caseInsensitive: NSString.CompareOptions
My question is how do I interpret this? This is supposed to mean that caseInsensitive
is type String.CompareOptions
?
Do I stack this on options: caseInsensitive: String.CompareOptions
?
I'm so new at this. I know python and that's about it but I love learning these new languages.
Upvotes: 0
Views: 469
Reputation: 578
Wow at least now I understand the documentation. lol I changed it to:
let range = tmp.range(of: searchText, options: NSString.CompareOptions.caseInsensitive)
Upvotes: 1