Cinema Trivia 2 Behind the Scene
When Apple introduced SwiftUI in 2019 WWDC, I knew I want to adopt it for Cinema Trivia. I also quickly realized that I had to abandon the source code for the original app and start fresh. This clean break allowed me to make other technological changes as well. Cinema Trivia 2 (CT2) was born.
Replacing Storyboard with SwiftUI was perhaps the biggest change. I personally did not have any issues with Storyboard. It worked well for me because I am a one-man shop. However, grievances with Storyboard from large development teams were well known. Apple’s response was SwiftUI, a declarative UI language. Since its syntax is based on Swift, you can develop the whole app in one language. SwiftUI had a lot of bugs in the beginning but situation improved over time. Some features are still missing, i.e. gesture recognizer. I do like that accessibility is built-in, a feature that I have to admit that I often overlook myself. Overall, I was able to implement various views of the app across wide range of device screen sizes without much compromise (with a little help from a third-party package mentioned later in this post).
Along with SwiftUI, I adopted Combine, Apple’s answer to reactive programming. Apple had embraced MVC for a long time, so Combine was a major paradigm shift. I did not have to write much code here because SwiftUI took care of a lot of basic plumbing on the UI level for developers. View controllers were gone. Classes remained but updated to manage observable properties.
Adopting SwiftUI & Combine means CT2 can only be run on devices with iOS 13 or higher. Apologies to owners of devices still on older iOS.
Another major change was using third-party SQLite driver instead of Core Data. My main issue with Core Data on the original Cinema Trivia was access to the database. Core Data wants to “hide” it, even from developers, which is not practical in my use case (read-only, easy to update). I got it working in the original app by figuring out where it was created and how to manually update it. I was kind of bending the best practice rule and wanted to avoid that trouble this time around. In CT2, I adopted SQLite.swift, a third-party driver that supports Swift and Apple Package Manager (APM). The experience was very pleasant. XCode imported the package without any issue. Writing Swift code to access the database and retrieve information was fairly easy and straight forward. Sorry, Core Data.
Using third-party SQLite driver also opens the door on porting CT2 to Android. Core Data is definitely not a showstopper here, but I cannot re-use its code in Android if I adopt it. I know there is Realm, but I really do not need an ORM here.
Another third-party package I adopted in CT2 development was DeviceKit. Since CT2 is mainly a text app, I want to display the characters as large as possible without looking obnoxious. It would also be easy on the eyes as well. One issue I had during development was fitting all the characters on small screen devices (<= 4.7″). Long titles often got truncated on small screen devices, so I had to use smaller fonts on such devices. That was where DeviceKit come in. While I could have written similar code without using third-party package, DeviceKit made it cleaner and helped out SwiftUI in the process.
While the development took quite some time with plenty of obstacles and frustrations in the beginning, the overall experience was educational and refreshing. Onto the next project.