Mallow's Blog

SwiftUI – Modern way of developing Apps for Apple platforms

Introduction

SwiftUI is a modern declarative UI designing framework introduced by Apple at WWDC19 for developing applications for iOS, iPadOS, macOS, watchOS and tvOS. It’s not write once, run everywhere. It’s learn once, develop for any platform in the Apple ecosystem.

Let’s see what are the advantages and tradeoffs of using SwiftUI and how the developer and product managers/product owners can make use of it. We mostly talk about iOS, but it applies to other platforms as well. 

Apple docs,
SwiftUI is a modern way to declare user interfaces for any Apple platform. Create beautiful, dynamic apps faster than ever before.

Development

  • SwiftUI takes less development time and cost than the UIKit(traditional framework for developing iOS and iPadOS apps) due to its declarative nature and single point of implementation. With UIKit, we need to design UI components separately and need to connect them with code to proceed with business logic. There are too many areas to concentrate on UIKit which is time-consuming and error-prone, whereas in SwiftUI, designing the UI in code is the only option that is declarative, easy and fast. 
Simple login screen with it’s code
  • As we are designing the UI and business logic in code, we can reuse the code more conveniently than UIKit, which again reduces the time.
  • Since SwiftUI is very young, not all UI counterparts of UIKit are available in SwiftUI. As Apple has one or another way of backward compatibility, we can use UI components from UIKit in SwiftUI and vice versa, which makes SwiftUI more powerful. 
  • In UIKit we need to maintain the consistency between the business data and UI which is not easy in general. In SwiftUI, we will define how the UI should look when the state of our business data changes, then it’s SwiftUI’s responsibility to maintain the consistency between the data and UI.
  • Live preview is very useful to get realtime updates in the UI as we update our code. No more building the whole app to see the surprise bugs in the new change. Instead, we can get it on live!!
Live preview demo
  • Can design any sort of complex UI and UX with ease in SwiftUI which might not be easy in UIKit. SwiftUI shines when the app supports multiple device sizes like the iPhone and iPad as it handles most of the heavy lifting for us. 
  • Assume a simple login screen that needs 4 – 6 hours of efforts in UIKit can be achieved with 60 – 70 % of efforts with more additional benefits in SwiftUI like accessibility support, dark mode, multiple screen sizes and orientation, etc…
  • Achieving a complex animation in UIKit needs additional knowledge in CoreAnimation framework, which is not needed with SwiftUI. Implementing Animation in SwiftUI is more simple and efficient than UIKit, as SwiftUI takes care of everything for us from rendering to performance optimisation.
  • Apple has added more UI components and improvements to SwiftUI in WWDC20. Apple has already started pushing SwiftUI to the mainstream by releasing a new framework that is completely written in SwiftUI. Eg, WidgetKit
  • Providing supports for the latest OS and Swift versions will be simple than UIKit as we have everything in code and a single place to concentrate

Testing

  • Developer testing time will be very minimal due to the state-driven nature of the SwiftUI
  • The bugs count due to developer mistake might get reduced as we no need to concentrate on multiple things when developing apps using SwiftUI
  • Adapting UI to different screen sizes is not easy always and it needs development and QA testing time which can be reduced in SwiftUI

Tradeoffs

  • SwiftUI is available from iOS 13 and we need to go with UIKit if we need to give support for the older version of iOS. The good thing is that the majority of the iOS and iPadOS users are running on the latest OS(iOS14) which supports SwiftUI. Check the below image for more details,
This image has an empty alt attribute; its file name is iOS-and-iPadOS-Usage.png
iOS and iPadOS usage
Image courtesy: Apple
  • We might face some unexpected issues at the framework level as SwiftUI is young and not matured like UIKit. 
  • Apple might change the existing APIs in new releases, as it is in continuous development. 
  • There is no backward compatibility for lower OS versions.
  • Objective-C developers need to learn Swift language to use SwiftUI.

We have started and kept exploring the SwiftUI from day 1 and worked on multiple internal projects and demo to understand the fundamentals of SwiftUI. We can expect more improvements and updates about SwiftUI in WWDC21. Product owners/managers can quickly convert their idea as a working app using SwiftUI. Watch this space for more updates about SwiftUI.  

Karthick Selvaraj,
iOS Team,
Mallow Technologies.

Leave a Comment

Your email address will not be published. Required fields are marked *