How to develop iOS apps in 2021

 

Photo by Marvin Meyer on Unsplash

Language

When you open Xcode, and create a new project the first choice is the programming language: Obective-C or Swift?
Today I am convinced that the best choice is to start a project in Swift, and in general I think that this language, introduced by Apple in 2014 is modern and mature but also way more readable then Obj-c.
Because that it helps to bring more developers to the platform and allows you to work in a neat and clean way.

Swift 5.5

I use is the latest released version of Swift: 5.5. The most interesting innovations in my opinion of this version are:

  • Async/Await (doc)
  • Actors (doc)
  • Codable synthesis for enums with associated values (doc)

Writing Swift code is a pleasure for readability and it is also a language that facilitates functional programming. There is no doubt about the choice and about keeping up with the latest version, since since version 5.0 the ABIs have been stabilised and therefore there is no risk of painful code migrations to support updates.

Architecture

The choice of the architecture to use inside a projcet is always a very hot topic. I have been working for some time with a Redux oriented architecture that is giving me a lot of satisfaction: The Composable Architecture.

The Composable Architecture

The great advantages of an architecture of this type are:

  • Centralized state: it allows you to have a single source of truth in the app. Keeping it always up-to-date makes the whole app aligned smoothly and instantly.
  • High testability: TCA has been designed test-oriented, and ioffers a suite of tools to simplify also hard test (like a way to mock time!).
  • Clear separation of responsibilities: dependencies and responsibilities are clear and well divided and the architecture guides the developer to work in a compliant manner.
TCA unidirectional flow

User Interface

Surely UIKit is the most mature framework for user interface made by Apple but the overwhelming novelty of a declarative UI, very easy to write and to maintain in my opinion is worth considering. Also for most needs, it is easier, and faster to write a UI in SwiftUI.

SwiftUI

So this is why I work in SwiftUI using version 2.0 which fill some small gaps present at launch.

What do I like?

  • Declarative UI: it’s wonderful to write UI, and SwiftUI allows you to do it in an elegant way. With this approach, reviewing PRs or resolving conflicts even related to interface is easy and understandable to anyone.
  • Integration with TCA and MVVM: fully supported by TCA and MVVM oriented the approach with SwiftUI forces the developer to separate the View from the Model and helping by design to keep separate responsibilities.
  • UIKit support: much of what doesn’t yet exist natively in SwiftUI can be imported from UIKit and in some case using a protocol named UIViewRepresentable so in a super easy way.

The only negative note is navigation. The tools offered are very poor, and the solution I decided to adopt is to use UIHostingController that contain the View and rely on UIKit navigation.

External Dependencies Manager

Swift Package Manager

Among the many alternatives every external dependency I use has added support for SPM, so I was able to discharge Cocoapods.
Probably in terms of performance and integration with CI, it was not the most stable choice but I really believe in SPM and I think it will be better and better going forward.

CI / CD

Fastlane + Bitrise

I use Bitrise as a full-featured mobile CI/CD in the cloud, because it supports every platform so well.
To package everything automatically Fastlane always gives me a lot of satisfaction, and especially in the Swift version!
With Fastlane Swift I could in fact easily integrate some steps such as the creation of specific builds, or the upload of dSYMs, or the automatic running unit tests at each commit easily and saving time. All this while continuing to write Swift code, which makes Fastfile easy to maintain even for other iOS developers!
Lately I’ve been exploring Fastlane Match for iOS certificate management, so I don’t have any more worries about this issue either.

Post a Comment

2 Comments