DA6. UiKit vs SwiftUI¶
In 2019, Apple introduced a brand-new framework that offers developers a new way to create user interfaces (“Introduction to SwiftUI,” 2021). Using this framework, the user interface is created programmatically, with swift code only, thus replacing the traditional storyboards. Compare and contrast UIKit and SwiftUI frameworks. In your responses to your peers, compare and contrast your points to those of your peers.
According to (Apple, n.d., UIKit), UIKit is a framework that provides various components to build Apps for IOS, IPadOS, and TvOS; but you still need AppKit to write UIs for macOS apps, TVUIKit To develop tvOS apps, and WatchKit for watchOS apps (AppCode, 2022).
SwiftUI is another framework by Apple that came a decade (or a bit more, exactly in 2019) after UIKit; which gave developers the ability to write one unified code for all Apple platforms, that is, the code that your write for iOS is easily portable to watchOS/macOS/tvOS (AppCode, 2022).
The text will compare both frameworks in various aspects, including the following:
- Code Style: UIKit uses imperative approach, while SwiftUI uses declarative approach; the difference is that -imperatively- the exact details must be listed out one by one, while -declaratively- the developer only needs to specify the desired outcome (AppCode, 2022).
- Code Size: SwiftUI source code is much shorter than UIKit source code; part of this is due to the declarative style of SwiftUI, and that SwiftUI implicitly does some work for managing states, and rendering the UI as needed, while you have to manually bind state to UI in UIKit. (Emini, 2023).
- Layout: SwiftUI uses VStack and HStack to layout views vertically and horizontally where the framework automatically handles resizing and positioning of views. UIKit requires the developers to manually set the frame and constraints of each view (Emini, 2022).
- API Coverage: SwiftUI is still relatively new, and it does not cover all the APIs that UIKit has. For example, SwiftUI
TextEditor
has less capabilities than UIKitUITextView
(Hudson, 2023). - Adoption: UIKit has been around for a long time, which means that a lot of applications are built using it, thus, a person must know UIKit to be able to maintain these applications. SwiftUI is still new, but it is fully compatible with UIKit (Hudson, 2023).
- Support: As UIKit is much older than SwiftUI, it is easier to find answers or help online for UIKit than SwiftUI; plus more third-party libraries for UIKit. (Hudson, 2023).
- Storyboards: Storyboards allowed developers to visually design users interfaces with little to no code. UIKit uses storyboards, while SwiftUI does not (AppCode, 2022).
- Minimum IOS Version: SwiftUI requires IOS 13 or later, while UIKit requires IOS 9 or later (Jeroen, 2022).
- Widgets: SwiftUI has widgets, while UIKit does not; you can still embed SwiftUI widgets within a UIKit-based app (Jeroen, 2022).
References¶
- AppCode. (2022). Mastering SwiftUI. AppCoda. https://www.appcoda.com/learnswiftui/swiftui-basics.html
- Apple. (n.d.). SwiftUI Developer Documentation. Apple Developer. https://developer.apple.com/documentation/swiftui/
- Apple. (n.d.). UIKit Developer Documentation. Apple Developer. https://developer.apple.com/documentation/uikit
- Emini E. (2023). UIKit vs SwiftUI: A Developer’s Dilemma. Medium. https://levelup.gitconnected.com/uikit-vs-swiftui-a-developers-dilemma-1d2b2e5d0149
- Hudson, P. (2023). Answering the big question: should you learn SwiftUI, UIKit, or both? https://www.hackingwithswift.com/quick-start/swiftui/answering-the-big-question-should-you-learn-swiftui-uikit-or-both
- Jeroen, L. (2022). UIKit vs. SwiftUI: How to Choose the Right Framework for Your App. Stream https://getstream.io/blog/uikit-vs-swiftui/