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

preview_player
Показать описание
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
Рекомендации по теме
Комментарии
Автор

Thanks Karin! I really like this tutorial series and is really useful! Keep up the good work

lucagfc
Автор

Thanks Karin! I really appreciate you did all of tutorial stuffs. I wanna know more about how to apply modular to swiftUI and how we should separate code into different layers in order to organize them easily or reuse them in other projects.

言って-xe
Автор

Nice video! I have a question, Is there any particular reason you used @ObservedObject to pass viewModels to *ListViews instead of .environmentObject() modifier? Or it's just a preference?

kironet
Автор

hello again, still the same problem with SONGS MODEL: let collectionExplicitness, trackExplicitness: Explicitness? I have it marked optional but still the data returns an error saying unexpected collectionExplicitness, trackExplicitness nil

dugrut
join shbcf.ru