On iOS applications, architecture
I’ve seen countless tweets and stories lately about iOS app architecture. I’ve been a massive fan of trying new architecture on iOS. In the past, I have worked with Redux / TCA-like architecture because I believe unidirectional data flow is the only way to have a good & robust codebase.
Glose on iOS is built using Redux (so we can share architecture decisions between the frontend, iOS & Android clients), and I’ve made various open source applications like MovieSwiftUI using a Redux like (& lite) architecture for SwiftUI:
GitHub - Dimillian/MovieSwiftUI: SwiftUI & Combine app using MovieDB API. With a custom Flux…
MovieSwiftUI is an application that uses the MovieDB API and is built with SwiftUI. It demos some SwiftUI (& Combine)…
But with my recent SwiftUI work on the Medium app and some other open source projects, I’ve come to some realizations:
- SwiftUI allows you to make a very powerful self-contained system with a minimal amount of code.
- SwiftUI offers a very clean data flow; it’s built in & simple to understand.
- I don’t want to add a boilerplate above SwiftUI anymore because it’s tedious and, most of the time, unnecessary. And it creates superfluous friction when onboarding new engineers on the team.
- I can achieve very clean, testable, and maintainable architecture with clean & barebone MVVM.
SwiftUI allows far simpler architecture because you can write very little code to achieve a good result.
So, the next time you start a SwiftUI application, ask yourself which architecture you should use. Try a simple MVVM architecture, make small views, small view model, everything private, and use State, Published, Observed, and Observable objects. If you need something available to your whole app, make an EnvironmentObject and inject it at the app level. These are just a few examples.
Did you see the excellent data flow documentation from Apple?
Here are the three absolute best WWDC videos you need to watch about the SwiftUI data flow and underlying mechanisms:
Data Essentials in SwiftUI - WWDC20 - Videos - Apple Developer
Data is a complex part of any app, but SwiftUI makes it easy to ensure a smooth, data-driven experience from…
Data Flow Through SwiftUI - WWDC19 - Videos - Apple Developer
SwiftUI was built from the ground up to let you write beautiful and correct user interfaces free of inconsistencies…
Demystify SwiftUI - WWDC21 - Videos - Apple Developer
Peek behind the curtain into the core tenets of SwiftUI philosophy: Identity, Lifetime, and Dependencies. Find out…
Once you’re done with those videos, you’ll have this 💡above your head.