HACKER Q&A
📣 gregkerzhner

How do you write quality iOS codebases?


I have been doing both front end development and iOS development for 5 years. I have found that on the front end, its gotten pretty easy to write clean maintainable code. Tools like Redux lets you cleanly move businesses logic out of the view layer and React allows you to have an easily written declarative interface.

iOS seems pretty far behind in code quality. Most iOS projects I have seen have thousands of lines long view controllers containing tons of logic, globals everywhere, 200 line functions, little to no unit testing, and no architecture. For those experienced iOS devs out there - do you have healthy iOS code bases you are proud of, and what do those look like from an architecture standpoint?

I have personally tried to introduce different types of architectures like MVVM and even Redux, but this has always been rocky on iOS, both from a tech standpoint because you are working against the ecosystem, and from a human perspective because (and this is a huge generalization) a lot of iOS devs tend to have an old school mentality and don't see the issues I am pointing out as problems - thats just how things work on iOS.

I would love to hear from someone that has experience cleaning up messy legacy iOS codebases, or examples of healthy iOS architectures that are open source.


  👤 taway555 Accepted Answer ✓
I'm currently at a company where our iOS product has millions of paying customers. FWIW:

We run a flavor of the coordinator pattern + MVVM. We use delegation to handle messaging between view models and view controllers. Services are currently handled by a super ugly singleton, but that's a by-product of legacy architecture. New features usually inject the service directly into the view model.. and there has been some talk in potentially moving the service to the coordinator to mimic a unidirectional data flow.

The issues you mention, i.e. globals, lack of unit testing, fat view controllers and lengthy functions... none of that stuff, if included in a pull request, would pass our code review. So generally we self police each other to avoid code smell.


👤 jamil7
I have a similar skillset to you and to be fair I've seen some pretty horrible React codebases in my time as well. You're correct though the architecture story is far behind on iOS, SwiftUI and Combine are attempts to address this and in my opinion they work really well. MVVM and Redux / Elm style architectures are really trivial to implement now. There is also a push for more functional approaches in general, if you look at videos from talk.objc.io or pointfree.co both of these focus on functional approaches to common architecture patterns. I hope that these recent developments from Apple are a signal of things to come in terms of providing better developer experience and insentives to use the platform's toolkit. To remain relevant I feel Apple has a huge amount of work to do in this area, documentation, XCode improvements and making SwiftUI a proper UIKit competitor (currently you will have to combine them for anything non-trivial).