Thank you friends, please enjoy!
Starter File: https://www.froggystudios.com/partners/Reu...
Finished Project: https://github.com/nraptis/SwiftUI-MVVM-Na...
MVVM (Model View View Model) is the cornerstone architecture for modern mobile application development. There are a lot of people trying to use MVVM with SwiftUI and 99% of them are doing it wrong because they do not adequately manage the lifecycle of detail views. I present a modern rendition of MVVM SwiftUI architecture that uses NavigationStack to do data-driven navigation. The data-linking and lifecycle-management of the view models is handled correctly. I've gone through over 100 different possible configurations for doing proper navigation with MVVM in SwiftUI. This is the very best one, which I am sharing with you. This navigation skeleton is of enterprise quality, capable of scaling to the needs of a large and complex application. The navigation methodology can be nested infinitely, so long as device memory permits it. I built this with web services, database communication, and other expensive asynchronous tasks in mind. Please reach out if you have any questions!
Mini Corrections:
At 41:10, it should say "Views call intent functions on View Models"
Macro Corrections:
How can this be done while keeping the back button? The ViewModels can be used as objects for the Navigation. It seems like the back button will not remove from the NavigationPath.
I have "Deprecated" this video, as I am waiting for a solution which works with the back button and also with the navigation stack + navigation path. Dear Apple: Please make the back navigation automatically free up resources. I have done an analysis. There's something fundamentally different about "navigationPath.removeLast()" and tapping the "back" button on the navigation bar. The back button leaves a whole mess of things in the memory graph.