Chaining dependent network requests in Swift with Combine | iOS Dev Live Mentoring

  Рет қаралды 50,297

Essential Developer

Essential Developer

Күн бұрын

Пікірлер: 28
@rajdhakate617
@rajdhakate617 3 жыл бұрын
Wow. You guys made it seem so simple
@captainmichaelj2321
@captainmichaelj2321 5 ай бұрын
How can apply similar logic for Firestore requests? This looks so elegant and simple. However, my firestore requests are full of dispatch groups and chained network request codes.
@EssentialDeveloper
@EssentialDeveloper 5 ай бұрын
Hi! You could wrap the Firestore requests in Combine publishers.
@leoyu4782
@leoyu4782 3 жыл бұрын
on 9:25, you mentioned there was a dependency between the two requests, we could use FlatMap. Can you please explain why the dependency would make FlatMap a good candidate for chaining the two requests ? thanks!
@EssentialDeveloper
@EssentialDeveloper 3 жыл бұрын
Hi Leo! `FlatMap` allows you to transform elements from an upstream publisher into a new publisher. So, in this case, we transform the received result of the first request into a new publisher to load the second request. Docs: developer.apple.com/documentation/combine/publishers/flatmap
@roh9934
@roh9934 Жыл бұрын
It is also very important to note that flatMap works only when the Error Type of both Publishers are same.
@ThatCronus
@ThatCronus 2 жыл бұрын
This was extremely helpful. Thank you. What if I wanted loadUserDetails() to also return the User? AnyPublisher
@EssentialDeveloper
@EssentialDeveloper 2 жыл бұрын
Hello Joe! In this case, you can Map the result of the Zip publisher to add the User in the tuple ✅
@Sebastian-jy8nh
@Sebastian-jy8nh 2 жыл бұрын
What about async-await taking in consideration? Assuming we've got iOS 15 as min. iOS version
@EssentialDeveloper
@EssentialDeveloper 2 жыл бұрын
Hi Sebastian. Async/Await also composes well when chaining dependent requests. You can perform one request at a time without completion blocks ✅
@shaileshphalgune3813
@shaileshphalgune3813 2 жыл бұрын
What if we want to chain the requests in such a way that, second request should be called only if first request is successful.. ? How can we do that ?
@EssentialDeveloper
@EssentialDeveloper 2 жыл бұрын
Hi! FlatMap is only called when the request is successful ✅
@Neonyziee
@Neonyziee Жыл бұрын
Can we make a chain that behaves in a manner if any of the chained or concurrent requests fail, publisher gives an error?
@arbenjusuf
@arbenjusuf 3 жыл бұрын
How to communicate Loader results to Controllers? Are we using an adapter with a callback? Or is it OK to sink and receive loader AnyPublisher results in ViewModels? And from VM, Controllers get changes stream?
@EssentialDeveloper
@EssentialDeveloper 3 жыл бұрын
Hi! It depends on what you're trying to achieve. If you want to decouple the ViewModel from the Loader, you can use an Adapter to direct the results to the ViewModel. The same with the Controller!
@OG4TheStreet
@OG4TheStreet 3 жыл бұрын
Waw, this is awesome guys, thanks a lot for this beautiful content, this is the first time I am seeing Zip in action
@fiqrihafzain2820
@fiqrihafzain2820 Жыл бұрын
where is this code lives? use cases or repository?
@EssentialDeveloper
@EssentialDeveloper Жыл бұрын
Hi! Network requests live in the infrastructure layer.
@FrancescoChiusolo
@FrancescoChiusolo 3 жыл бұрын
How would you do that prior to iOS 13 where Combine is not available? PS: avoiding closures of course :), in the same declarative way.
@EssentialDeveloper
@EssentialDeveloper 3 жыл бұрын
Hi Francesco! By creating composable objects with a shared polymorphic interface (pretty much how Combine does it!). We showed how to do it in other mentoring sessions - but they're only available to students of the iOS Lead Essentials now.
@justknot4481
@justknot4481 3 жыл бұрын
i find some similarity with pyton 🤔🙃
@ganeshmodi2565
@ganeshmodi2565 3 жыл бұрын
not able to hit bell icon getting "This action is turned off for content made for kids"
@EssentialDeveloper
@EssentialDeveloper 3 жыл бұрын
Probably a bug on the KZbin app because this content is flagged as *not* for kids! Please, try again from a different browser/app. Thanks!
@petrushoc
@petrushoc 3 жыл бұрын
I.flatMap { you }
Multithreading and Concurrency in iOS apps | iOS Dev Live Mentoring
35:40
Essential Developer
Рет қаралды 8 М.
When mom gets home, but you're in rollerblades.
00:40
Daniel LaBelle
Рет қаралды 64 МЛН
Миллионер | 2 - серия
16:04
Million Show
Рет қаралды 1,7 МЛН
Who’s the Real Dad Doll Squid? Can You Guess in 60 Seconds? | Roblox 3D
00:34
Занятие 20: Combine | Swift | UIKit
1:22:28
Ildar Zalyalov
Рет қаралды 2,1 М.
Swift - Result Type - Cleaner Network Calls
12:07
Sean Allen
Рет қаралды 20 М.
This is How I Scrape 99% of Sites
18:27
John Watson Rooney
Рет қаралды 135 М.