diff --git a/enzevalos_iphone/InboxViewController.swift b/enzevalos_iphone/InboxViewController.swift index c9693df3bbff95cdf7585573a474873f34497d2a..743d76b4952b6f2cef2503b43cd7ffd6989240ce 100644 --- a/enzevalos_iphone/InboxViewController.swift +++ b/enzevalos_iphone/InboxViewController.swift @@ -39,6 +39,10 @@ class InboxViewController: UITableViewController, InboxCellDelegator { } } } + + // how many seconds should the app wait before processing search bar input + var searchDelay = 0.5 + // holds the currently active search timer (if it exists) so it can be terminated if a new character is typed before the execution var searchBarTimer: Timer? @IBOutlet weak var lastUpdateButton: UIBarButtonItem! @@ -250,19 +254,20 @@ class InboxViewController: UITableViewController, InboxCellDelegator { } /// searches a given string with a delay so that the entire client doesn't lag if the inbox is very big + // TODO: Perhaps think of a better name func startSearch(searchText: String, scope: Int = 0) { if #available(iOS 10.0, *) { if let searchBarTimer: Timer = self.searchBarTimer { searchBarTimer.invalidate() } - self.searchBarTimer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false, block: { _ in - self.filterContentForSearchText(searchText, scope: scope) + self.searchBarTimer = Timer.scheduledTimer(withTimeInterval: searchDelay, repeats: false, block: { _ in + self._filterContentForSearchText(searchText, scope: scope) }) } } - private func filterContentForSearchText(_ searchText: String, scope: Int = 0) { + private func _filterContentForSearchText(_ searchText: String, scope: Int = 0) { var records = [KeyRecord]() if scope == 0 || scope == 3 { records += folder.records.filter({ (record: KeyRecord) -> Bool in