Clean Architecture for SwiftUI

Clean Architecture for SwiftUI

This article is also available in Korean.

[…]

But something has happened recently. This “something” is so significant, that the majority of the architectural patterns used for iOS will soon become history.

I’m talking about SwiftUI. It’s not going anywhere. Like it or not, this is the future of iOS development. And it’s a game-changer in terms of the challenges we face when designing the architecture.

[…]

For more complex scenarios, Views can reference an external ObservableObject, which in this case can be a distinct ViewModel.

[…]

Let’s consider this quick example of the MVVM module for a SwiftUI app.

[…]

That guy had a WORKING prototype of SwiftUI in 2017!

Does it feel like we’re on a reality show where SwiftUI, a half-orphan kid, has just got to know who his father is?

Anyways, what interests us is whether we can use any other ELM concepts for making our SwiftUI apps better.

I followed the ELM Architecture description on the ELM language’s web site and… found nothing new. SwiftUI is based on the same essences as ELM:

[…]

There is a practical example of using Coordinators in SwiftUI by quickbirdstudios, however, to my state, it’s overkill. Plus, this approach has several drawbacks, such as granting Coordinators full access to all ViewModels, but you should check it out and decide for yourself.

[…]

So if we distilled the requirements of the Clean Architecture through the peculiarity of SwiftUI, we’d come up with something like this:

[…]