filmov
tv
How to run multiple network requests and complex data flow in SwiftUI - iTunes Search API - PART 4/7

Показать описание
In this part of the iTunes search API app, the logic will get a lot more complex. I want to work on the search tab that has multiple sections for showing songs, albums and movies. Which means that when the user enters a new search term, the app needs to execute 3 different network requests.
I am going to reuse as much of the existing logic as possible.
We will first work on displaying the picker for selecting a media type e.g. all, movie, song or albums. Then, I have to build the logic that shows different lists depending on the selected media type.
In order to share the fetched data from the server, I am going to create 3 view models that fetch the data. These view models will be passed down to different view parts.
In order to connect the search term with the view models that execute the network request, I will create data streams. Part of this automatic fetching and updating behaviour is using Combine.
The passing of data between different parts of the app is done with onAppear and onChange view modifiers
You can also use onReceive if you want to pass a property from a view model to e.g. another view model.
Overview
00:00 Introduction
04:35 Search view with media type selection
25:06 data flow between search text property and view models
34:46 summary onChange, onAppear and onReceive
If you liked what you learned and you want to see more, check out one of my courses!
👩🏻💻 Combine course
⬇️ Project starter files for this tutorial:
⬇️ Project end:
#SwiftUI #AsyncImage
I am going to reuse as much of the existing logic as possible.
We will first work on displaying the picker for selecting a media type e.g. all, movie, song or albums. Then, I have to build the logic that shows different lists depending on the selected media type.
In order to share the fetched data from the server, I am going to create 3 view models that fetch the data. These view models will be passed down to different view parts.
In order to connect the search term with the view models that execute the network request, I will create data streams. Part of this automatic fetching and updating behaviour is using Combine.
The passing of data between different parts of the app is done with onAppear and onChange view modifiers
You can also use onReceive if you want to pass a property from a view model to e.g. another view model.
Overview
00:00 Introduction
04:35 Search view with media type selection
25:06 data flow between search text property and view models
34:46 summary onChange, onAppear and onReceive
If you liked what you learned and you want to see more, check out one of my courses!
👩🏻💻 Combine course
⬇️ Project starter files for this tutorial:
⬇️ Project end:
#SwiftUI #AsyncImage
Комментарии