From 95df24857d36e9637735fec3ec019d33775e3977 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Sat, 6 Feb 2021 17:39:06 -0600 Subject: [PATCH] Update PreferencesViewController.swift --- .../General/PreferencesViewController.swift | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/Clocker/Preferences/General/PreferencesViewController.swift b/Clocker/Preferences/General/PreferencesViewController.swift index e8dd92e..abcb8af 100644 --- a/Clocker/Preferences/General/PreferencesViewController.swift +++ b/Clocker/Preferences/General/PreferencesViewController.swift @@ -466,16 +466,8 @@ extension PreferencesViewController { } private func findLocalSearchResultsForTimezones() { - searchResultsDataSource.timezoneFilteredArray = [] let lowercasedSearchString = searchField.stringValue.lowercased() - - searchResultsDataSource.timezoneFilteredArray = searchResultsDataSource.timezoneArray.filter { (timezoneMetadata) -> Bool in - let tags = timezoneMetadata.tags - for tag in tags where tag.contains(lowercasedSearchString) { - return true - } - return false - } + searchResultsDataSource.searchTimezones(lowercasedSearchString) Logger.info(searchResultsDataSource.timezoneFilteredArray.debugDescription) } @@ -613,7 +605,7 @@ extension PreferencesViewController { } private func installTimezone(_ timezone: Timezone) { - guard let dataObject = searchResultsDataSource.filteredArray[availableTimezoneTableView.selectedRow % searchResultsDataSource.filteredArray.count] as? TimezoneData else { + guard let dataObject = searchResultsDataSource.retrieveFilteredResult(availableTimezoneTableView.selectedRow) else { assertionFailure("Data was unexpectedly nil") return } @@ -763,7 +755,7 @@ extension PreferencesViewController { } private func cleanupAfterInstallingCity() { - guard let dataObject = searchResultsDataSource.filteredArray[availableTimezoneTableView.selectedRow % searchResultsDataSource.filteredArray.count] as? TimezoneData else { + guard let dataObject = searchResultsDataSource.retrieveFilteredResult(availableTimezoneTableView.selectedRow) else { assertionFailure("Data was unexpectedly nil") return } @@ -784,8 +776,8 @@ extension PreferencesViewController { let data = TimezoneData() data.setLabel(CLEmptyString) - let currentSelection = searchField.stringValue.isEmpty == false ? searchResultsDataSource.timezoneFilteredArray[availableTimezoneTableView.selectedRow % searchResultsDataSource.timezoneFilteredArray.count] : - searchResultsDataSource.timezoneArray[availableTimezoneTableView.selectedRow - 1] + let currentSelection = searchResultsDataSource.retrieveSelectedTimezone(searchField.stringValue, + availableTimezoneTableView.selectedRow) let metaInfo = metadata(for: currentSelection) data.timezoneID = metaInfo.0.name