Swift UI Part 1 (Introduction)

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

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

What is Swift UI?

Swift UI 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 Swift UI 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 Swift UI is a declarative framework, it states that we tell Swift UI for the elements we want and how we want. We declare the elements, modifiers(properties) to the elements.

How is Swift UI 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 Swift UI.

  • 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 Swift UI.
  • 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 Swift UI 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 Swift UI

  • 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 Swift UI framework. More articles are coming soon with a detailed explanation of the various aspects of this framework.

Next Article in the series: Starting with Swift UI.

Resources:
Swift UI

We can help you with your
App Design & Development needs.

Stay-Up-To-Date

Keep in the loop with the latest in emerging technology and Mutual Mobile