BLACK FRIDAY SALE: Save big on all my Swift books and bundles! >>

How are you guys accessing Environment objects within your view models?

Forums > SwiftUI

Hi guys, using MVVM in SwiftUI seems like a good idea. I like the seperation of concerns. However I also find it introduces other challenges that can be quite combersome to overcome. One of the challenges I'm facing is having access to Environment based objects within my view models (SettingsManager, UserManger, etc).

I'd love to know how you guys are going about achieving this level of access.

Any help would be welcome.

Thanks

Sam

   

I pass them via reference in my views/view models.

   

Hacking with Swift is sponsored by RevenueCat

SPONSORED In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app. Oh, and it's free if your app makes less than $10k/mo.

Learn more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.