Incremental search
[email protected]
class ViewController: UIViewController, UISearchBarDelegate, UITableViewDataSource {
...
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return results.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
cell = ...
item = results[indexPath.row]
cell.textLabel.text = ...
return cell
}
func searchWithText(text: String) {
realm
.objects(Location)
.filter("...")
.sorted("...")
.addNotificationBlock { (...) in
...
}
...
tableView.reloadData()
}
func searchBar(searchBar: UISearchBar, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
...
searchWithText(text)
return true
}