What is SwiftUI?
SwiftUI is Apple’s new declarative framework for building user interfaces for all Apple devices. This framework can be broken down into two essential components: views and state.
State management is an integral part of SwiftUI development, and there are many different ways of working with the state. In which State represents the data associated with a view.
You will learn how to manage all the states of a screen using only one state variable with very easy steps by following the MVVM software design pattern.
Today we are going to learn about a state holder to separate business logic from UI components.
ViewModel has a longer lifecycle than the view. so ViewModel can preserve its state across UI changes.
Here, we can extract business logic from views and put it inside ViewModel in a way that is easy to understand and maintainable for future developers.
For detailed implementation, check out original article.
The full source code is available on Github.
Top comments (0)