nalexn / clean-architecture-swiftui

SwiftUI sample app using Clean Architecture. Examples of working with CoreData persistence, networking, dependency injection, unit testing, and more.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: Handling multiple loadables

mnightingale opened this issue · comments

How would you deal with views that require more than one loadable?

Your view private var content: AnyView always switches on the status of one loadable, but I think I have a situation where I need to wait for multiple loaders to have loaded before drawing a loaded view.

I figure I could use one loader and pass it a tuple, but that seems really messy.
I wonder if I want some kind of loader container could be the way to go?

Hey @mnightingale
Your case is somewhat similar to the one discussed here.

You should go from what works best for your UI. Can it show something meaningful when the first request has loaded but the second one is not?

If the answer is no (UI would still have to show the same loading indicator) - then you should use one Loadable which eventually provides all the required data collected from all the requests. UI should see the data loading process as a single transaction, which eventually either fails or succeeds, and it should not care or know how many requests are actually being made.

If the answer is yes (UI can show something after the first request is complete) - then you'd introduce separate Loadable states and configure your UI to render appropriately for different combinations of these two states.

You can also define a struct for collecting all the returned data, and use it instead of the tuple

Thanks @nalexn that's a really thorough answer.