Browse Source

Abstracting away some unneccesary public deets from SearchDataSource.

pull/92/head
Abhishek 4 years ago
parent
commit
cc08fb3c44
  1. 30
      Clocker/Preferences/General/SearchDataSource.swift

30
Clocker/Preferences/General/SearchDataSource.swift

@ -29,8 +29,8 @@ class SearchDataSource: NSObject {
"EST": ["florida", "new york"],
"EDT": ["florida", "new york"]]
var filteredArray: [Any] = []
var timezoneArray: [TimezoneMetadata] = []
private var filteredArray: [Any] = []
private var timezoneArray: [TimezoneMetadata] = []
var timezoneFilteredArray: [TimezoneMetadata] = []
init(with searchField: NSSearchField) {
@ -52,6 +52,15 @@ class SearchDataSource: NSObject {
return finalArray[row]
}
func retrieveFilteredResult(_ index: Int) -> TimezoneData? {
guard let dataObject = filteredArray[index % filteredArray.count] as? TimezoneData else {
assertionFailure("Data was unexpectedly nil")
return nil
}
return dataObject
}
private func setupTimezoneDatasource() {
timezoneArray = []
@ -123,6 +132,23 @@ class SearchDataSource: NSObject {
return false
}
func searchTimezones(_ searchString: String) {
timezoneFilteredArray = []
timezoneFilteredArray = timezoneArray.filter { (timezoneMetadata) -> Bool in
let tags = timezoneMetadata.tags
for tag in tags where tag.contains(searchString) {
return true
}
return false
}
}
func retrieveSelectedTimezone(_ searchString: String, _ selectedIndex: Int) -> TimezoneMetadata {
return searchString.isEmpty == false ? timezoneFilteredArray[selectedIndex % timezoneFilteredArray.count] :
timezoneArray[selectedIndex - 1]
}
}
extension SearchDataSource: NSTableViewDataSource {

Loading…
Cancel
Save