HomeiOS Developmentios - What's the easiest way to inject router into viewmodel in...

ios – What’s the easiest way to inject router into viewmodel in SwiftUI?


I am engaged on a SwiftUI app with 100+ screens, and I am looking for a scalable technique to deal with navigation logic inside ViewModels, reasonably than in Views.
At present, with the intention to carry out navigation, I get router from my atmosphere, and assign it to viewmodel like this:

@EnvironmentObject var navigator: FlowNavigatorPath

.onAppear {
    viewModel.navigator = navigator
}

This works however I am in search of some generic resolution to keep away from doing that in each display screen. Answer that lets me entry navigator immediately from viewModel.

For little Reference: Our present android group is already working with resolution to this. I’m not very clear on that however the gist is that they have a base view and a base viewModel. Each viewModel and View in app conform to their related base courses. Now in that base courses, they’ve in some way managed to speak navigator. After which of their little one viewmodel class, they simply entry navigation in viewmodel.

Any assist could be appreciated. Apologies if I used to be not clear sufficient.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments