Getting Started With the VIP Clean Architecture Pattern

In this tutorial, you’ll learn how to utilize the VIP clean architecture pattern to develop apps for Apple platforms while building a SwiftUI for ordering an ice cream. By Danijela Vrzan.

4.3 (12) · 9 Reviews

Download materials
Save for later
Share
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

Implementing Navigation Using Router

In UIKit, you use segues to navigate and pass data between views. But, in SwiftUI, you use NavigationLink inside the View.

Do you see an issue here? The view ends up handling both the navigation and data passing logic. This isn’t the way of clean architecture.

Check out this diagram:

Diagram of VIP pattern with added router component that talks to the view in a bidirectional way

You could add Router to extract the navigation logic out of the View. It seems a bit counterintuitive when it comes to SwiftUI, but it’s doable.

The router component has two protocols: RoutingLogic and DataStore.

RoutingLogic contains navigation methods. If your view navigates to multiple views, the router handles all.

DataStore contains the data you need to pass to the destination view. You create it inside the interactor. That way, the router can get the data it needs to pass to another view and doesn’t know about the interactor.

NOTE: If you’d like to learn more about the router, check the Routing to the Detail View section of Getting Started with the VIPER Architecture Pattern tutorial.

Where to Go From Here?

You can download the completed project files by clicking Download Materials at the bottom or top of this tutorial.

VIP was created as a solution to massive view controllers in UIKit. It’s meant to make building larger apps and adding new features easier on long-term projects. All you need to do is add a new scene, create your components and start adding the logic.

You’ve seen how it forces you to write shorter methods with single responsibility, making your code easier to unit test. But the architecture relies on protocols with often-complicated naming and responsibilities.

It’s hard to maintain the separation between view and presenter. Sometimes, the presenter calls the view without preparing the UI and can feel useless and create boilerplate code.

But like every other architecture out there, it has its advantages and disadvantages. It’s up to the developer to decide what architecture is best for the project and the team.

To learn more about MVVM, the most popular architecture for SwiftUI apps, check out MVVM with Combine Tutorial for iOS.

If you want to learn more about implementing modern clean architectures in your iOS apps, see the Advanced iOS App Architecture book and take your skills to the next level.

We hope you enjoyed this tutorial. If you have any questions or comments, feel free to drop them in the discussion below.