A single-screen weather app written in Swift/SwiftUI that follows a Model-View-ViewModel (MVVM) architecture,
which helps maintain separation of concerns and ensures a clean and scalable codebase.
-
Model:
API Data Model : Represents the structure of weather data, including properties like temperature, humidity, wind speed, weather conditions, etc. This model is used to decode data from the weather API. -
ViewModel:
WeatherViewModel : Acts as an intermediary between the Model and View layers. Also responsible for making API requests to fetch weather data from the weather service provider OpenWeatherMap and formats it for presentation.
LocationViewModel: Manages location services, retrieving the user's current location and passing it to the WeatherViewModel for weather data retrieval. -
View:
ContentView : This is the main SwiftUI view that presents the weather information to the user.
Subcomponents : SwiftUI Views -
Service:
Location Service : Interacts with the device's location services to fetch the user's current location. -
Common:
This contains reauseble tools shared app wise, like extensions, helper functions, etc. -
Network:
Endpoint : url used to call the open weather API, which contains the configuable parameter and the APIKey.
NetworkManager : network layer with generic functions to make http calls and map data to data models
Get the API key from and configure it in the endpoint file
enum Endpoint {
..
private var apiKey: String { return "&appid=APIKEY" }
..