Skip to content

AntPRams/Trip-Planner

Repository files navigation

Trip planner

App made with the requirements provided, 
those are listed below with comments regarding my thoughts and details about the implementation of each. This app was developed using MVVM architeture.

App requirements

  1. Download and parse information:
  • The APICaller is the object that have a generic method used to fetch a model, then the ConnectionsService use the caller to fetch and map the data accordingly. The Service is a protocol that can be extended or used for similar purposes.  
  1. The user should be able to select any departure city and any destination city available (even if a direct connection between the two cities is not available):
  • I've mapped all the cities, origin and destination, into an array to have them available in both SearchFields. The user will be able to pick one city from a list that will popup if the text matches any city name from the ones provided.  
  1. The purpose of this app is to find the cheapest route between the two cities that the user select and to show the total price in a label in the same page:
  • This was the trickiest part. I already knew about the Dijktra's algorithm but I never had to implement it. I've tried some solutions made from scratch, but where some did work perfectly in other paths failed miserably. Then I stumble upon an Apple framework, GameplayKit. So, with the help of GKGraph i've managed to create a path calculator that was able to provide all the paths available between two given nodes. Then i only had to check which was the cheapest.  
  1. Use coordinates available in the JSON to show the cheapest selected route on a map:
  • I've started the project with XCode 15, but we all know how well behaved are those betas, I drop out and move to XCode 14, since I didn't had the access to the new SwiftUI map API's, I had to create a UIViewRepresentable to be able to add polylines to a map and add it to a SwiftUI view  
  1. BONUS: To select the cities use a text field with autocomplete (from the list of the available cities you get from the JSON):
  • This was done with the help of folding using the query and the city while filtering. The suggestions are presented in a view below the SearchField that's being edited.

UI Details

The header has three buttons:

  • Search: calculate a path between the two given inputs
  • Clear: clears the inputs in both SearchFields and removes the path detail views if displayed
  • Refresh: download and parse information from the given url

Both SearchFields will display a dropdown list if the input matches any city available. If the user tap any city row it will automatically fill the focused SearchField with the name of the choosen city. Everytime the user search for a path, the app will validate if all the fields are filled correctly, if not an alert will be displayed with the designated error for each case. When a patch is found the map and the trip overview will be displayed.

Tests

Unit tests covers 63,8% of the app, with a large portion of the remainder being covered by UI tests

Developed with:

  • macOS Ventura 13.5.1

  • XCode 14.3.1

About

Code challenge

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages