Start with SwiftUI

Should we use SwiftUI right now ?

William Gho
3 min readMar 15, 2021

As we know SwiftUI launched end of 2019 as an interface toolkit for Swift to building iOS Apps (Apple Watch, Apple Tv, iPhone, iPad, and Mac). SwiftUI is well known as a declarative framework because we can customize our user interface to what we want to.

So, UIKit replaced by SwiftUI ?

I’ll say no. Because SwiftUI still used aspects of UIKit(TextView, UIScrollView, etc). Besides that, Apple has made the SwiftUI compatible with every property and process in UIKit, and then we don’t need to change existing code. But, we can combine UIKit and SwiftUI.

The different part of SwiftUI and UIKit

SwiftUI is a declarative framework and UIKit is an imperative framework. In real life sample, when we are in the restaurant and want to book the place. In an imperative way, “I see the table behind the door is empty, and then we going to walk over there”. In a declarative way, “Table for two, please”.

As we can simplify, with imperative we concern with How we going to get a table. We need to list out the steps to be able to show How we’re going to get a table. with declarative, we concern with What we want because the restaurant already has the operation to handle customers seat.

Next, the difference in performance. In UIKit, every view is implemented from a class called UIView that had many properties and methods (backgroundColor, constraints, etc) and that’s how inheritance works. In SwiftUI, views are struct.

As we understand, struct only conforms to view protocol that no extras values inherited from the parent class. It’s simpler and faster than classes.

Last, isolating state. It helps us to think about a cleanly isolating state. As we know, classes can change their values freely, which can lead to messier code. By producing views that don’t mutate over time, SwiftUI encourages us to move to a more functional design approach. So, our views become simple convert data into UI.

Conclusion

The SwiftUI is worth trying and putting on your learning list because Apple was concerned problem of constructed UI too. It helps us to create Apple Ecosystem devices easily.

SwiftUI already provides two-ways binding as a property wrapper, which will in turn stash it away and causes the UI to refresh automatically.

And so many magical things that we should try. But would it be good for us to start right away learning the SwiftUI instead of UIKit?

Personally, I encourage you guys to learn some knowledge in UIKit, because many of the companies have developed their applications using UIKit. But, It possible for the next 2–3 years everything will be integrated with SwiftUI and You have a big plus point to have some knowledge of SwiftUI.

In the next part, I will share code about SwiftUI implementation. Or if you want to see what I do, you can follow me at:

--

--