SwiftUI - The UIKit's Successor

Introduction

Let’s start with Apple’s Own Definition:
“SwiftUI is an innovative, exceptionally simple way to build user interfaces across all
Apple platforms with the power of Swift. Build user interfaces for any Apple device using just
one set of tools and APIs. With a declarative Swift syntax that’s easy to read and natural to write,
SwiftUI works seamlessly with new Xcode design tools to keep your code and design perfectly in sync.
Automatic support for Dynamic Type, Dark Mode, localization, and accessibility means your first line
of SwiftUI code is already the most powerful UI code you’ve ever written.”

Although it is NOT a replacement for UIKit/AppKit, take it or not, UIKit/AppKit is about to die slowly
just like Objective-C and SwiftUI is going to replace UIKit/Appkit in the iOS/macOS platforms. 

On SwiftUI Views:

“SwiftUI Views are functions of state and not a sequence of events like UIKit”, meaning the views
are created based upon your data/model and most importantly they’re structs aka value types thus
cannot be referenced meaning they’re immutable and doesn’t allow any manipulation like
adding/removing subviews. 
However, you can use certain property wrappers like @State, @Binding, @BindableObject to
create the views dynamically based upon the updates to the property of your model aka whenever
your data changes.


Let’s look at the several Pros & Cons of SwiftUI:

Pros:

  • Adaptability: Easy to learn and use the declarative syntax as opposed to UIKit imperative approach
  • Cross Apple Platforms: Native support across Apple platforms
  • Features: You get a ton of automatic support like ‘Dynamic Type, Dark Mode, Localization, Accessibility’ out of the box
  • Semantic Colors: SwiftUI framework changes the colors automatically based upon the dark/light mode so that you don’t have to deal with that complexity anymore 
  • UIKit Compatible: Can be used alongside UIKit with UIHostingController
  • Reactive Programming: If you’re a fan of Reactive programming, you’ll love this. SwiftUI provides ways to map your data to the view’s aka data flow as streams with the help of property wrappers & the brand new Combine framework
  • Multiple Previews: SwiftUI previews allow you to view multiple devices & orientation versions of the same UI with hot reloading which helps in faster UI development
  • Animations: Adding animations to SwiftUI views is a breeze
  • Performance: SwiftUI views are structs aka value types and thus has less performance impact while creating the views

Cons:

  • Deployment: Works only on iOS13 and up devices aka no backward compatibility to older iOS devices
  • Less support: SwiftUI is relatively new and hence doesn’t offer much help with debugging
  • No Access to view hierarchy: Doesn’t allow you to debug the view hierarchy in Xcode Previews
  • UIKit/AppKit: All the knowledge that you’ve gained so far for over a decade or have mastered with UIKit/AppKit is nearly obsolete now
  • AutoLayout: SwiftUI doesn’t support AutoLayout. All you Auto Layout knowledge is also obsolete now and you have to learn the SwiftUI’s new layout system
  • Storyboard/Interface-Builder: All the storyboarding stuff/tooling is gone, all your related knowledge is obsolete now
  • Value Types: SwiftUI views are structs aka value types and thus views cannot be referenced or accessed or modified/mutated

Learn by building an app:

If you’re looking to jump-start by learning the fundamentals by building out an app with the SwiftUI framework, this would be a good start.

Conclusion:

Though it is up to us to adapt to the SwiftUI framework or choose to stay using UIKit/AppKit. 
For the long term sustainability and in order to stay relevant & competitive in the marketplace, you need to learn and master SwiftUI if you’re planning to keep developing apps for users on Apple’s platforms.
After all, it is not all bad at all, fortunately, Apple engineers have done a good job with SwiftUI, adapting to use it, is the future we’re driving towards which looks well and good. 
Always remember that: “‘Change’ is the only thing in this world that is a constant, everything/anything else is variable”, these golden words are stuck with me after having heard it from our Thalaivar.

Comments

Popular posts from this blog

Free Hand Drawing on Google's Map View

Android from iOS Guy's Perspective

Free Hand Drawing on Maps with MapBox SDK