SwiftUI 5.5 API Data to List View

Paul Allies
Oct 13, 2021

Many times we need to make API calls to fetch data to display in a list. Here, I show how to do that with SwiftUI. To illustrate the structure of the application, let’s look at the following diagram:

The Todo APIService

We need to create an API service to send the network requests. We will use URLSession. Here we have one method to fetch all todo item and deserialise them to [TodoItem]

The Todo ViewModel

The view model in turn uses the API Service to fetch todos to then publish

The Todo View

Finally we have the view which watches the ViewModel for any todo list state changes. The todo list is display in the view. On list appear the view makes the api call.

--

--

Paul Allies
Paul Allies

No responses yet