I’ve been keen on developing a Swedish BIP-39 compliant wordlist for some time now — using my favourite programming language Swift of course! A BIP-39 wordlist is a list of 2048 words that are easy to remember. In the context of BIP-39, each word can be used to encode a random integer in the range 0–2047 (11 bits). Where say the integer 3 is mapped to the fourth word in the wordlist. This can be used as a human-friendly serialization of random bytes, e.g. …


Did you read the first part?

This is the continuation of my previous article Single-Lince Controller: SLC, please read that before reading this, otherwise, the contents of this article won’t make any sense.

Advanced ViewModel

Let us have a look at a more complicated ViewModel and View, where we make use of the populate method. Let’s take a look at a simple SignIn scene implementation:

The view is simple, a usernameField and a passwordField that actually are some subclass of UITextFieldcapable of displaying validation error. For which we have some reactive property rx.validationfor toggling the result of the validation. We have a signInButton, which starts as disabled. arranged by a UIStackView. We also have some kind of LoadingView which is hidden by default and for which we have some reactive property rx.isLoading


TL;DR: In this article, I present the SLC: Single-Line ControllerUIViewController with a single line of code:

Introduction

In this article, I present the core parts of a new iOS architecture I call the Single Line-Controller or SLC for short. Which is a derivation of MVVM but done right, because there is no ‘C’ in ‘MVVM’, right? Thus no room for the malicious Controller.

Image for post
Image for post
Reference: Sundell’s tweet https://twitter.com/johnsundell/status/1014137138517102592

Disclaimer 1: This architecture is extremely custom. If you are a big fan of vanilla MVC will most likely detest what I present below.

Disclaimer 2: The code snippets presented below are made up revolving around the common use case — Authentication — thus it might contain typos or compilation errors. …


Image for post
Image for post
Manual mapping of value types

Reflection in Swift is easy using the struct Mirror, with it we can inspect the names and types of properties in an instance of a struct or an instance of a class (soon you’ll see why it was important to bold the words).

Imagine we have a struct called Book which looks like this:

struct Book {
let title: String
let author: String?
let published: Date
let numberOfPages: Int
let chapterCount: Int?
let genres: [String]
}

Then we can create an instance of Book, let’s create Harry Potter!

let book = Book(title: "Harry Potter", author: "J.K. Rowling", published: Date(), numberOfPages: 450, chapterCount: 19, genres: ["Fantasy", "Best books…

About

Alexander Cyon

Cryptocurrency and DLT evangelist. Freelancing IT consultant and app developer in love with Swift.

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