diff --git a/enzevalos_iphone/InboxViewController.swift b/enzevalos_iphone/InboxViewController.swift index f61f272221a128d697165ae650e5e79bcc499c7d..8dbf26242ffe2aabfc07d0182b9642f47f40639c 100644 --- a/enzevalos_iphone/InboxViewController.swift +++ b/enzevalos_iphone/InboxViewController.swift @@ -253,18 +253,22 @@ class InboxViewController: UITableViewController, InboxCellDelegator { return searchController.isActive && !searchBarIsEmpty } - /// 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 + /** + searches a given string with a delay so that the entire client doesn't lag if the inbox is very big + + - parameters: + - searchText: srtring to look for + - scope: where to search (look at _filterContentForSearchText) + */ 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: searchDelay, repeats: false, block: { _ in - self._filterContentForSearchText(searchText, scope: scope) - }) + // check if a search has been scheduled already and stop it to prevent multiple searches + if let searchBarTimer: Timer = self.searchBarTimer { + searchBarTimer.invalidate() } + + self.searchBarTimer = Timer.scheduledTimer(withTimeInterval: searchDelay, repeats: false, block: { _ in + self._filterContentForSearchText(searchText, scope: scope) + }) } /** diff --git a/enzevalos_iphone/ListViewController.swift b/enzevalos_iphone/ListViewController.swift index d6fcb37a964886841170a531b70a07521d45c902..4983b0bc098a3e6d61171e0dd6cf266aeadd719c 100644 --- a/enzevalos_iphone/ListViewController.swift +++ b/enzevalos_iphone/ListViewController.swift @@ -110,14 +110,14 @@ class ListViewController: UITableViewController { } func startSearch(searchText: String, scope: Int = 0) { - if #available(iOS 10.0, *) { - if let searchBarTimer: Timer = self.searchTimer { - searchBarTimer.invalidate() - } - self.searchTimer = Timer.scheduledTimer(withTimeInterval: searchDelay, repeats: false, block: { _ in - self.filterContentForSearchText(searchText, scope: scope) - }) + // check if a search has been scheduled already and stop it to prevent multiple searches + if let searchBarTimer: Timer = self.searchTimer { + searchBarTimer.invalidate() } + + self.searchTimer = Timer.scheduledTimer(withTimeInterval: searchDelay, repeats: false, block: { _ in + self.filterContentForSearchText(searchText, scope: scope) + }) } /**