Ask HN: How do you write quality iOS codebases?
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.
5 comments
[ 2.7 ms ] story [ 16.3 ms ] threadWe 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.
From what I’ve seen you can supply state to a view and it’ll take care of the rendering for you.
Ive been out of the iOS game for about two years and now getting back into it. Have you had luck convincing your organization to use SwiftUI? What have been the painpoints? I am finding that people on my team are pretty traditional, even hesitating to use autolayout, so pushing SwiftUI might be an uphill battle.