SwiftUI: A Flourishing Recipe for iOS Development

Apoorv Joshi
The Lenskart Blog
Published in
4 min readSep 23, 2022

--

Introduction

With the advent of new technology and creative approaches, iOS app development is moving into a new era. Not too long ago, Apple released iOS 13, and with it came the modern approach to iOS app dev in the form of SwiftUI. The developers working in the Apple ecosystem have rarely been spoiled with options. After a long period of Objective-C and C++, Swift programming language brought about a wind of change and innovation as the language evolved. However, we have only had the UIKit framework ever since iPhone OS 2 in 2008. And with time, UIKit went on to become a powerful and mature framework, it is now, with over 14 years of collected documentation and knowledge, releasing elegant and high-performing apps in the market. The iOS app for Lenskart also owes its current state to this very framework.

SwiftUI, on the other hand, brought new paradigms and workflows to the field, aiming to smoothen out and streamline the seemingly anachronic development process. Just like how Swift came and took the world by storm, becoming almost a staple and intimately linked with the iOS app development process, SwiftUI is the new trend aiming to succeed its predecessor, which at this point has potentially peaked and is almost saturated. Of course, now that we have options/competition, it is understandable that some comparisons would be drawn between UIKit and Swift UI app architecture.

UIKit

User Interface Kit, or UIKit allows the developer to create interfaces that can manage inputs and interactions between the system, the user, and the developer. Various objects such as UIView and its subclasses facilitate the aforementioned content interaction within the application. It tends to be an imperative approach i.e., specifies steps(flow) needed to reach a certain goal or target. It is choke full of different design assets and elements that also offer functionalities to the users. The core aspect of UIKit can be surmised in the following points

  • It provides the window and views architecture to help facilitate user interaction.
  • Its vast collection of ready-to-use design elements saves a lot of time that would otherwise be wasted on creating them from scratch.
  • It offers an event handling architecture, allowing multi-touch input and more.
  • Jam-packed with features such as animation support, drawing support, text management, search support, app extension support, and much more.

SwiftUI

SwiftUI, on the other hand, tends to incline towards the declarative approach( specifies the logic but not the flow). Since SwiftUI can be considered the future go-to framework for iOS dev, it's important that we address both the pros and the cons that it offers.

Pros

  • SwiftUI is easy to learn and efficient. The code is simple and clean.
  • Until the SwiftUI is in full swing, UIHostingController can be used to integrate the SwiftUI view into the UIKit hierarchy.
  • Provides mechanisms for reactive programming such as the Combine framework.
  • A very progressive and convenient feature of SwiftUI is a live preview, which automatically reflects the changes made without the need to run the application.
  • It no longer needs an interface builder, instead, the Canvas(live preview) provides the same utility while also maintaining a clean and readable code.
  • A big issue with UIKit has always been associated with its auto layout constraints. SwiftUI rectifies this by introducing stack views( HStack, VStack, and ZStack). All views created on SwiftUI are valid views.
  • Since the storyboard is now replaced by code, it opens the possibility of the creation of reusable views.

Cons

  • SwiftUI only supports iOS 13 and above, and XCode 11 and above, radically abandoning the users of old versions of iOS.
  • There is still not much data and documentation on online communities and forums regarding SwiftUI. So you could very well stumble upon an issue that could make you wait for quite some time before you are able to get the doubt cleared.
  • One big drawback is that the absence of a storyboard means the inability to examine the view hierarchy in XCode Previews.

As stated earlier, Lenskarts iOS consumer app revolves around the UIKit build, and the team is getting ready for a big migration. Recently the iOS team launched the Widgets for the app, which utilizes the WidgetKit extension following the SwiftUI model, integrated with the already existing UIKit-based app. The successful launch is the first step toward transitioning to a newer framework. Weekly sessions and discussions are being conducted, and the outlines are being drawn to ensure that nothing goes amiss during the shift. As the application userbase is expanding massively and considering the future plans that Lenskart have in store for their consumers, keeping the pace of development on par with the creative minds and upcoming features is necessary. Keeping this in mind, SwiftUI fits our future needs perfectly.

Simply speaking, SwiftUI brings a massive change to the table with regard to code clarity, management, and convenience. It gives a massive boost to development speed and enables multiplatform compatibility. Not to mention that SwiftUI is still pretty young and has the potential to grow into a mature and powerful tool with time. But even until that happens, SwiftUI is already being implemented, mixed with the UIKit model as it slowly grows and takes over the market entirely.

--

--

Humilde Escritor. A computer Science undergrad forging my own unconventional path, trying to pen down my thoughts to the best of my abilities.