I’m currently working on my app with MVVM and a combination of views made with UIKit and SwiftUI and having some trouble figuring out how to handle network callbacks between the views. All network operations are done with Async/Await.
How my app works goes, there is a button inside a UIKit view and, when you touch it, it will send you to a collection view made with SwiftUI.
So, the specifics of my problem are stemming from, say, that I’m making a collection view with a LazyVGrid in SwiftUI and I want it to show only when each and every item, there are unknown number of them, on it has finished receiving data from the server. Right now, The items are laid on the LazyVGrid via ForEach loop and, since there’s no network completion handler in place, the items blink from the placeholder to the view intended when their network call is finished. Thus, my first question is, Is there any way to handle multiple callbacks from every SwiftUI view inside a ForEach loop and process the LazyVGrid after the items have finished receiving data through network?
After that, how do I send a callback that the LazyVGrid is ready to show to the UIKit view? I want to do this because I want to place a loading screen until the LazyVGrid is completed.
I think I’m making this app way harder than it should be, but I decided to get out of my comfort zone and try to experiment with something complicated view-wise.
So far, I have tried making a Published variable that goes up when the items are finished, but, since I have to send a callback to the UIKit view as well, it’s no use.
Thanks for reading this, and I appreciate your help.
Have a nice day.
Jinoccoli is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.