Swift UI: A brief introduction

Swamita Gupta
ACM VIT
Published in
3 min readJun 8, 2020

During WWDC 2019, Apple introduced SwiftUI, a new framework that complements its open-source compiled programming language for iOS, macOS, watchOS, tvOS, Linux, and other platforms alongside an amazing development experience in Xcode 11.

What’s all the hype about?

SwiftUI is an advanced and yet a simple way to develop user interface across Apple platforms with the supremacy of Swift. It is an entirely new paradigm and changes how the world thinks about UI building for iOS apps. It allows iOS developers to build a user interface using just one set of tools & APIs. Bid adieu to the complex UIKit code since SwiftUI powers you to now define what your iOS application’s UI should do with declarative languages.

With Dark Mode, accessibility, localization, and Dynamic Type, SwiftUI code can be termed as the most powerful UI code in iOS development.

This might pop up the following questions in your head

· What makes SwiftUI more preferable than others?

· Can SwiftUI replace the older UIKit and storyboard framework of iOS development?

· How do I learn SwiftUI?

Let us see for ourselves.

What makes SwiftUI more preferable than others?

1. Declarative code:

Declarative programming is “the act of programming that conforms to the mental model of the developer rather than the operational model of the machine.” It means writing codes with declarations. Unlike imperative programming in which you are instructed on how to perform a task, you can now simply tell your user interface what to do using the declarative SwiftUI.

This has made programming in swift easier and efficient and saves both- your time and maintenance.

2. Design tools:

Using SwiftUI, your XCode 11 environment now includes new simple design tools like drag and drop and many more, to give you a seamless developer experience. Many of the visual editors are also available within the code editor, so you can also use inspectors to discover new modifiers for each control, even if you prefer hand-coding parts of your interface.

With a new feature called dynamic replacement, the canvas is always in sync with the adjoining editor making it quicker and prettier to see your written code built on the interface. Xcode recompiles your changes instantly and inserts them into a running version of your app, visible, and editable at all times.

3. Native on all Apple platforms:

It enables programmers to layout a UI and then adjust how it looks and works across multiple platforms in ways appropriate to each device, with the aim to “learn once, apply everywhere”.

Using SwiftUI, your apps gain incredible native performance and take advantage of the proven technologies, controls and user experience.

Can SwiftUI replace the older UIKit and storyboard framework of iOS development?

Unlike Objective-C and Swift, SwiftUI does not replace UIKit, and you can use both in the same application. Many portions of SwiftUI are built directly on top of your existing UIKit components, UITableView(List), for example. Many components are now renamed for better and easier developer experience. However, SwiftUI doesn’t support storyboard.

As long as Apple makes the SwiftUI compatible with the methods and properties of UIKit, your code doesn’t need to change. Besides, you can also mix views from UIKIT and SwiftUI. As you would expect, there are some new controls rendered by SwiftUI but not UIKit. However, industry experts believe that SwiftUI will mask the UIKit’s behaviour in two years.

How do I learn SwiftUI?

Due to the growing popularity of SwiftUI, it can be learnt from various sources online. Apple has also released official tutorials of SwiftUI. In case you come across any doubts, you can always find answers on the Apple documentation page of SwiftUI. The links are given below.

1. https://developer.apple.com/xcode/swiftui/

2. https://developer.apple.com/tutorials/swiftui/

3. https://developer.apple.com/documentation/swiftui/

Various blogs, vlogs and online tutorials are also available to aid your progress in the field.

Conclusion

SwiftUI is a must-try for all the iOS enthusiasts out there. It is fully integrated with the XCode development experience and the native frameworks for Apple Watch, tvOS, and macOS apps. It lets developers specify UI with simple declarations and in practice, reduces hundreds of lines of code to just a few, simplifying the workflows for developers.

Try it out if you haven’t already!

--

--