diff --git a/Clocker/Onboarding/OnboardingSearchController.swift b/Clocker/Onboarding/OnboardingSearchController.swift index f6fe97fa..371474c1 100644 --- a/Clocker/Onboarding/OnboardingSearchController.swift +++ b/Clocker/Onboarding/OnboardingSearchController.swift @@ -84,8 +84,9 @@ class OnboardingSearchController: NSViewController { let selectedType = searchResultsDataSource.placeForRow(resultsTableView.selectedRow) switch selectedType { case .city: - let filteredGoogleResult = searchResultsDataSource.retrieveFilteredResultFromGoogleAPI(resultsTableView.selectedRow) - addTimezoneToDefaults(filteredGoogleResult!) + if let filteredGoogleResult = searchResultsDataSource.retrieveFilteredResultFromGoogleAPI(resultsTableView.selectedRow) { + addTimezoneToDefaults(filteredGoogleResult) + } return case .timezone: cleanupAfterInstallingTimezone() @@ -422,6 +423,8 @@ class OnboardingSearchController: NSViewController { private func resetSearchView() { searchResultsDataSource.cleanupFilterArray() + searchResultsDataSource.timezoneFilteredArray = [] + searchResultsDataSource.calculateChangesets() resultsTableView.reloadData() searchBar.stringValue = CLEmptyString searchBar.placeholderString = "Press Enter to Search" @@ -513,4 +516,8 @@ extension OnboardingSearchController: NSSearchFieldDelegate { // return true if the action was handled; otherwise false return false } + + func searchFieldDidEndSearching(_ sender: NSSearchField) { + self.search(sender) + } } diff --git a/Clocker/Preferences/General/SearchDataSource.swift b/Clocker/Preferences/General/SearchDataSource.swift index 2a83a106..93622ec1 100644 --- a/Clocker/Preferences/General/SearchDataSource.swift +++ b/Clocker/Preferences/General/SearchDataSource.swift @@ -75,6 +75,10 @@ class SearchDataSource: NSObject { } func retrieveFilteredResultFromGoogleAPI(_ index: Int) -> TimezoneData? { + if index >= filteredArray.count { + return nil + } + return filteredArray[index % filteredArray.count] }