For background, I’m nearing completion of an app I plan to publish. The app is built with SwiftUI and uses MVVM. As the project has evolved, my view model has grown quite large, with a view hierarchy 5 views deep. I include an environment object instance of my view model in nearly every view.
I came across this article in one of the newsletters I subscribe to. Since I’ve not seen this subject in any tutorial or discussion on CWC, I thought I’d mention it. The idea is to divide your view model into smaller “slices” and use only the slice you need for any given view. This will prevent the unnecessary re-rendering of views (when view model data that those views don’t depend on changes).
I plan to try implementing the idea in my project, but was curious as to whether anyone out there has tried it, or has thoughts or opinions. It seems like a good way to improve the efficiency of an app.