The project is an iOS app using Xcode 11.2.1 and Swift 5.
MVVM, which allows to separate business logic from controller and increases testablity.
There are two view controllers, CitySearchViewController and MapViewController.
It contains a SearchController to perform the searches and a TableView to show the results. it also contains ViewModel which manages the data to be shown on view It performs a segue to the MapViewController to show the map of the selected city.
Standard ViewController with a MKMapView. It gets the city as a parameter passed from CitySearchViewController.
CitySearchViewModel contains all the business logic and data that needs to be shown on CitySearchViewController
FilterUtil class is a helper class to filter data based on search criteria using binary search. Data is loaded from JSON file and the items are sorted and binary search is applied to filter data.
Sorted the given 200,000+ items and used binary search to find the start and last index (range) of the prefix match with given search word.
binary search is efficient for search in a sorted array, with worst case complexity of O(log n) comparisions.
There are two data clases: City and Coordinates:
- City is a Decodable struct that contains the necessary fields for the project. like name, country and searchkey
- Coordinates is in a struct that contains the latitude and longitude of the city. City contains a property
coordinatethat uses the lat and lon values to return a properCLLocationCoordinate2Dobject.
Data is fetched from cities.json file.
Testcases are written in BackBaseCitySearchTests class which tests the viewModel for valid and invalid city searches
There are no external dependencies to the project.
Thank you!