Eric Silverberg

Life in the outer layer of Clean MVVM is platform-specific

That’s what I call a View

At the outer layer of our Clean MVVM hierarchy are Views, including Activity and UIViewController, and these are represented by the blue 🔵 parts of our Clean architecture.

Image for post
Image for post

We can think of the view as the class that defines what to draw on the screen and how to draw it, but not when or why. The “when” is decided by the view model, and the “why” by the logic. Below is a summary of different types in this layer:

View classes should have only platform-specific code, related to what to draw — conditional business logic does not belong here. View classes should only interact with the ViewModel, not logic or repository classes. View classes can also be expected to implement navigation if we need to start a new UIViewController / Activity per user interactions. …


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.

Image for post
Image for post
Yes, this will be on the test

Below are the key points across all articles in this series, helpfully summarized:

Architecture


API classes initiate network calls to one remote service, specific to the Repository you are implementing. Though it may be tempting for your API class to itself interact with the network, don’t do it — instead, inject an HTTP client (such as Retrofit on Android) into your API class that itself provides general-purpose network access, including adding necessary authorization parameters and headers.

Image for post
Image for post
What you’re going to do to that network response

Each feature area is broken up into a specific interface that defines the necessary GET/POST/PUT/DELETE operations for that feature. API classes are always injected into Repositories. …


What comes after an API response?

Image for post
Image for post
This repository could probably use a refactoring, but those domain models sure look tasty. Photo by Marc Noorman on Unsplash

APIs are like the engines of apps — every app has them, and they provide the fuel that makes the app work. But what happens after an API call completes? How is the data managed, munged, and manipulated before it is (ultimately) rendered in a View on iOS or Android?

***

Perry Street Software has been publishing apps since 2010, and in this series of blog posts, we introduce the Clean MVVM architecture for consistent cross-platform code in Swift and Kotlin.

The center of our abstraction — Repositories and Domain Models — is the part that should also be most closely aligned from a code perspective. In our Clean architecture diagram, Repository and Domain Model classes are represented by yellow 🟡 . …


Explore the ecosystem of classes that power well-designed ViewModels

Image for post
Image for post
A forest is more than just trees, and a ViewModel is more than just Views and Models! (Photo by Lukasz Szmigiel on Unsplash)

Developers often make the mistake of thinking that, in an MVVM architecture, Model classes are all that live beneath the ViewModel layer, or maybe Models + API classes.

In our Clean MVVM architecture, we see that there is in fact a larger ecosystem of classes that all enable the ViewModel to do its work. The first and most overlooked of these enabling classes are called Logic classes.

Logic classes are stateless wrapper classes that apply conditional logic based on data retrieved from repositories.

Logic classes are represented by the red 🔴 parts of the diagram in our Clean architecture. A ViewModel updates its state or emits an event based on these decisions. Logic classes do not know anything about the View or the ViewModel. …


The best approach to writing tests is far from obvious

Man writing on paper
Man writing on paper
Photo by Jason Coudriet on Unsplash.

In the early days of mobile, client testing primarily revolved around UI testing. Apple shipped a technology called UIAutomation, which it ended up deprecating completely in 2016 with the release of Xcode 8. The Android testing samples repository did not get created until 2014.

Because of the top-down approach required by UI testing, tests will break if you significantly redesign your UI. Furthermore, UI testing does not by itself handle the various logical states that arise from dependent systems, such as network failure responses. Confirming that a button changes color when tapped is frequently less valuable than confirming the app responds correctly when receiving a 500 response from a server. …


Comparing Combine, ReactiveSwift and RxJava for tests

Image for post
Image for post
Multiple threads are beautiful but tricky!

In this series we introduced a Clean MVVM architecture for writing consistent code in Swift and Kotlin.


Everyone’s heard of a ViewModel, but what do they actually do?

Image for post
Image for post
A complex, early ViewModel (Photo by David Carboni on Unsplash)

From StackOverflow:

A view model represents the data that you want to display on your view/page, whether it be used for static text or for input values (like textboxes and dropdown lists) that can be added to the database (or edited). It is something different than your domain model. It is a model for the view.


A series on using Clean + MVVM for consistent architecture on iOS & Android

Image for post
Image for post
The bridge is Clean + MVVM

Mobile development has aspired toward “write once, run anywhere” since the earliest days of Java. When iPhone first launched, we saw companies like Facebook try to implement a generalized, WebView-based approach, before abandoning that effort and going native. Only a few years later in 2015, Facebook would try again with React Native, adopted with great fanfare by companies like Airbnb only to be undone a few years later.

About

Eric Silverberg

CEO, Perry Street Software. Developer. 🏳️‍🌈

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store