SwiftUI - The UIKit's Successor
Introduction
“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.
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.”
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:
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.
create the views dynamically based upon the updates to the property of your model aka whenever
your data changes.
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
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
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
Comments