Fetching remote data using Combine and visualizing it in SwiftUI
A common characteristic most mobile apps have is that they fetch data from a remote web service.
Given the asynchronous nature of the problem, it is often problematic when this is implemented in the normal imperative world.
However, it suits the reactive world nicely, as we'll see in this recipe.
We are going to implement a simple weather app, fetching the current weather and a 5-day forecast from OpenWeather, a famous service that also has a free tier.
After fetching the forecast, we present the result in a list view, with the current weather fixed on the top.
Getting ready
We start by creating a SwiftUI app called WeatherApp
.
To use the service, we must create an account on OpenWeather.
Go to the OpenWeather signup page (https://home.openweathermap.org/users/sign_up) and fill it with your data:
After confirming the login...