Regular view controller for fixing Clean Swift iOS architecture

You did it, Mary. You electrified the entire automotive industry.

What is regular view controller?

Writing view controller with some refactor skill and an emphasis on Swift language features.

Why regular view controller?

Every design pattern assumes you write dumb shit massive view controller.

The line up

What are the features of Swift?

// model update
title = "clean"
// view update
view.title = "clean"
var title = "" { didSet {view.title = self.title} }
var model = Model() { didSet {updateUI()} }

Comparison

Now we are ready to stack up against the cleanest of all clean architectures: Clean Swift.

Interactor
Presenter
protocol OrderProcessing {
var order: Resource{get}
var json: JSON {get set}
}
extension OrderProcessing {
func doSomething() {
order.get().onSuccess {json in self.json = json}
}
}
// view controller conforming OrderProcessing
var json = JSON() { didSet {updateUI()} }
var order: Resource{
// return a resource where you can get/post ...etc
}

Fixing the problems

  1. Strict type system doesn’t always help you
var orderDate: String {    // let dateFormatter = ... 
// let date = json["date"]...
// return dateFormatter.stringFromDate(date)
}
// in updateUI() called by property observer
view.date = orderDate

Recap

Let’s summarize what we’ve learned thus far.

  1. I just refactored Clean Swift with techniques. Architectures are built on language features and techniques. Clean Swift showed none.
  2. MVC is not only a suitable architecture, it is better than Clean Swift.
  3. Massive view controller problem is real, but that’s not what you should be competing against. Winning over something that is defined to be bad is not a win. You need to win over a half-decent refactored MVC that at least tries to use Swift features.

You did it Mary

--

--

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