mercredi 17 février 2021

Sharing data across SwiftUI app: better pattern to choose?

I'm working on delivery app, where I should have an access to shop (title, phone), auth (is logged in, user name, email) and cart (add/remove/clear) modules across the app.

For now I'm sharing all the data with EnvironmentObjects, but causes a mess in the code to inject some or all of those three "services" into each and every view (there are a lot of sheets).

Singlton can solve the problem, but AFAIK singleton is an anti-pattern, especially if I have even three singletons in the app. Is there any more efficient way to do this stuff? I use MVVM in the app.

Thanks in advance!

P.S. Any good resources about the topic (design patterns) are also more than welcome

Aucun commentaire:

Enregistrer un commentaire