SwiftUI Part 1 (Introduction)

Ankush Bhatia
Mutual Mobile
Published in
3 min readDec 26, 2019

This article includes the introduction to the SwiftUI framework, which is part of a series that will cover various aspects of this framework. This article might motivate you to use SwiftUI instead of UIKit to create a user interface in your applications.

What is SwiftUI?

SwiftUI is a declarative UI framework from Apple which lets developers write UI code in a new and better way than UIKit. As Apple says “Better Apps Less Code”, we can use SwiftUI to create user interface by writing less code and the good thing is that we only need to write one code that works on every platform.

What exactly is a declarative framework?

So in simple terms by saying SwiftUI is a declarative framework, it states that we tell SwiftUI for the elements we want, no matter how SwiftUI gets and implements it. We declare the elements, modifiers(properties) to the elements.

How is SwiftUI better than UIKit and AppKit?

The one problem I can think of right away is the conflicts we face in storyboards. Well, the storyboard is fun to create UI. It made our life easy. It is easy to understand the flow of the app by just looking into the storyboards. But it has a few trade-offs.

  • Hard to work in a team due to conflicts that come with storyboards.
  • We do not have much control over the code of the UI, as UIKit is writing code for us underneath.
  • We need to take care of AutoLayout and View Life Cycle while creating the UI.

Advantages of SwiftUI.

  • Multiple platform support.(iOS, macOS, watchOS, tvOS).
  • Easy to reuse UI elements. Since it is just code we can simply use any element or UI anywhere, we want to use.
  • Backward compatibility for UIKit elements. Meaning that if some UI elements you want to use from UIKit, we can write some code to make it happen. So technically speaking we can add any type of view in our application. This topic is discussed in detail in a separate article in this series.
  • With the help of live preview, we can see our UI as we write code which is not possible in the UIKit. The live preview is one of the best things I like about working with SwiftUI.
  • Easy to make changes to the existing UI code.
  • There is always less code we write as most of the time we will be just reusing it various platforms apple provides.
  • It is a win-win situation for every developer as now you do not have to learn AppKit separately as now you just need to write one piece of code. But this doesn’t mean someone who knows UIKit and AppKit is of no use. Knowing these frameworks is always helpful as sometimes we might need to use it in our code as well. But saying that I believe SwiftUI will evolve and will provide those elements also right in the framework.
  • It is also easy to read since it is a declarative framework.

Challenges in SwiftUI

  • Since Apple just released this framework, it is still in a very early stage. We can expect many new changes coming to the APIs.
  • The minimum deployment target of iOS 13 is required.
  • Most of the existing apps today support previous versions of the iOS and hence it is not possible for everyone to start working with the new framework, but in the future, everyone will be shifting to this framework, so it is a excellent time to learn SwiftUI.

I hope you enjoyed learning a few things about the SwiftUI framework. More articles are coming soon with a detailed explanation of the various aspects of this framework.

Also, feel free to follow me on Twitter for updates on upcoming articles. I am really excited to start this series, and any kind of suggestion and thoughts on the article are most welcome.

Next Article in the series: Starting with SwiftUI.

Resources:
SwiftUI

--

--