VIP Design Pattern SwiftUI

Here we are going to see a simple design pattern that can be used with the new SwiftUI. The VIP design pattern has basically three components as the name suggests,
1 . View in SwiftUI:
2. Presenter: Talks to the interactor for data and sends the data back to the view object by an observable object that conforms to ObservableObject protocol.
3. Interactor: Talks to the various data layers such as database, API calls etc.
Let us see with a simple example. We have to develop an app that displays a list of animals.
The animal view has reference to the animal presenter which conforms to ObservableObject protocol. When a published property is changed in an observable class, the view that holds the observed object is rendered again.
In this example, the presenter is the observed object in the animal view and the data source array in the presenter is the publishing property.
One the data in the presenter is updated from the interactor, the Animal view is reloaded with the updated data source.

Now we can see the handling of data flow seamlessly by the SwiftUI framework.

Please feel free to reach me at pratheesh_db@hotmail.com for help or queries.
See related:
