samedi 17 août 2019

SwiftUI and MVVM design pattern

  I am trying to get my head round how i can achive the following using the MVVM design pattern with SwiftUI.

I want to have only 1 instance of a networking operation queue (using OperationQueue) where any view model that needs to send any networking requests but i have heard that creating a Singleton is not preferred and i should be passing the networking queue object around where it is needed.

So if i create the instance of the network operation queue in the Scene Delegate and pass them into the ContentView initialiser and store it in an object there to then pass into the views then created.

This doesnt seem like good MVVM design practice as from what i understand the View should Own the ViewModel only?

What is the best way of achieving this?

Thanks

Aucun commentaire:

Enregistrer un commentaire