Skip to content

Latest commit

 

History

History
13 lines (7 loc) · 1.17 KB

File metadata and controls

13 lines (7 loc) · 1.17 KB

FeatureFactoryExample

An example project demonstrating proper handling of view models in SwiftUI + MVVM architecture.

See the accompanying posts:

Reddit

Linkedin

In the first version of FeatureFactory, the view model is created inside a .task modifier and unwrapped inside a ZStack. While functional, this approach can cause visible flickering in certain situations, since the view briefly renders before the view model becomes available.

An improved second version uses a lazy var to access the view model. This avoids any delay in instantiating the view model, eliminating the flickering side effects present in the original implementation. However it introduces a small overhead by allocating extra ViewModelState class on every view update.