kode: 2fa code organization app in swiftui

9 April 2024

An iOS/macOS app for organizing 2-factor authentication codes with support for seamless synchronization across devices.

I use 2-factor authentication wherever I can. Currently, I have 20 of them on my app. I used Google Authenticator to manage them for years since it was the simplest app (very unlike any other Google app). But after Google decided to update the app and automatically upload all of my accounts to its cloud, I decided it was time for a change.

I wanted an alternative that did not store my last line of defence on their servers. I also wanted to be able to access them on more devices than just my phone. The only logical option seemed like making my own app.

I do not care for UI design (in fact, I dislike it) so I wanted to use a solution with prebaked designs, and since I am well integrated into the Apple ecosystem the logical choice was to use SwiftUI.

SwiftUI is surprisingly easy to learn and there are so many tutorials out there (notably Hacking With Swift). Writing the basic phone app with was trivial and I was able to locally store and show all the codes in no time.

I used a library for generating the codes according to the TOTP algorithm and another one for scanning QR codes with the camera.

The first challenge was to transition to iCloud Keychain to store the account data. Not only did this allow me to not worry about the security of the user's data but it also gave me an easy way to synchronize the data between multiple devices. The official documentation for this part was arcane and hard to understand. Thankfully, the many tutorials online guide me through it fine.

The second challenge was to make a companion watch app. While the app itself was trivial to shape thanks to the UI in SwiftUI, synchronizing the data from the app to the watch was not an easy task.This part alone took probably 50% of the development time for this project. It also did not help that the connection between XCode and the watch was incredibly unstable. Sometimes, the watch app would fail to connect to the simulated app and sometimes, the watch was not visible at all.

Overall, my experience with SwiftUI and its promise to create one app for all platforms was a hit and a miss. My app for the iPhone worked flawlessly for the iPad but when it came to macOS, I had to fully rewrite it since there are so many mismatches between the platforms. For example, copying something to the clipboard uses completely different functions depending on the platform. This also meant that I had to include so many compiler directives like #if os(iOS).

Other than the interoperability aspect, I find Swift to be a great language to develop on. It is obvious that a lot of thought went into designing the language, especially for the developer experience. I would use Swift regularly if it was used outside of the Apple ecosystem.

The app is released on the App Store, you should check it out.

See this project on github.