Build the same app twice
A summary of architecting and testing apps in Swift + Kotlin
In our series on Clean MVVM, we have shared real-life lessons shipping a major mobile client on multiple platforms for more than a decade. Clean MVVM is an architectural approach for building consistent apps in Swift and Kotlin, to maximize architectural and code design re-use. At its best, Clean MVVM enables you to copy-and-paste Swift into Kotlin, or Kotlin into Swift, and just twiddle the syntax.
Below are the key points across all articles in this series, helpfully summarized:
Architecture
- The control flow is: View ➡ ViewModel ➡ Logic ➡ Repository ➡ API/Store
- Use Reactive streams when communicating state changes between layers
- Logic classes are stateless and can be composed
- Repository classes have state and should be global singletons injected via a DI system
- Models should be structs or sealed classes that use primitive types only
BehaviorSubject
/LiveData
/Property
/@Published
are your go-to primitives for data that needs to be available for the duration of a screen and changes at unpredictable intervalsPublishSubject
/Observable
/SignalProducer
/Publisher
are for events, typically as a result of user inputSingle
/Completable
/SignalProducer<Void>
/AnyPublisher
are for APIs and calls to local storage
Testing
- Use dependency injection for object construction in tests
- Only mock outer-layer classes — primarily network APIs
- Structure your tests narratively using BDD, and minimize the number of assertions per test (ideally only one)
- Use TestObserver classes (or their equivalent) to evaluate asynchronous streams
One more thing…
If you’re a mobile developer who enjoys app architecture, are interested in working for a values-first app company serving the queer community, talk to us! Visit https://www.scruff.com/careers for info about jobs at Perry Street Software.
More in the series
- Clean MVVM Intro
- ViewModels in Swift & Kotlin
- Logic Classes in Swift & Kotlin
- Repositories and Domain Models in Swift & Kotlin
- API classes in Swift & Kotlin
- Views in Swift & Kotlin
- Testing MVVM in Swift & Kotlin
- Testing Asynchronicity in Swift & Kotlin
- Clean MVVM Summary ← you are here
Other series you might like
Clean API Architecture (2021)
Classes, execution patterns, and abstractions when building a modern API endpoint.
Android Activity Lifecycle considered harmful (2021)
Android process death, unexplainable NullPointerExceptions, and the MVVM lifecycle you need right now
About the author
Eric Silverberg is the CEO and founder of Perry Street Software, publisher of two of the world’s largest LGBTQ+ dating apps on iOS and Android. He has been shipping mobile apps since 2010 and writing code since that english class book report in Hypertalk in 1995.