We develop both native and hybrid iOS and Android applications. Our focus lies on maximizing device capabilities and ensuring high performance for the challenges we are tackling. As mobile development technologies are constantly evolving, we often explore new methods and tech products when creating bespoke solutions for enterprise clients. SwiftUI is a notable product worth sharing and one we are looking to employ in a number of current engagements.
What is SwiftUI?
SwiftUI is an innovative and simple way to build user interfaces across Apple devices. SwiftUI is native on all Apple platforms and available on devices that support iOS 13+, Xcode 11, and Catalina.
SwiftUI uses declarative syntaxes to state what the user interface should do. For example, it is possible to write a list of items consisting of text fields, then describe alignment, font, and color for each field in a single line text editing. For example:
Some of the more compelling design tools include:
- Arranging components within the user interface by simply dragging controls on the canvas. Drag controls from the library and drop them on the design canvas or directly on the code.
- The Swift compiler and runtime are fully embedded throughout Xcode, so the app is constantly being built and run. The design canvas shows the live app. Xcode can swap edited code directly in the live app with “dynamic replacement”.
- Create one or many previews of any SwiftUI views to get sample data and configure almost anything users might see, such as fonts, localization, or Dark Mode. Previews can also display UI in any device and any orientation.
Benefits of SwiftUI over UIKit:
- It’s easy to get started with the basics. Apple has a great set of tutorials for getting used to building UIs with SwiftUI
and interacting with UIKit components from SwitfUI.
- It offers Live Preview. This is a convenient and progressive way to see the results of code execution in real-time without having to build.
- Refactoring UI is a simpler process. It’s easy to see when view code is getting long.
- It can be mixed with UIKit using UIHostingController.
- Developers can easily add dark mode to their apps and set it as the default theme, and users can easily enable dark mode. It just looks awesome.
- An application will no longer crash if the @IBOutlet association with the variable isn’t updated.
Like any framework, SwiftUI also comes with some limitations:
- Complex tasks don’t have a good example code yet. Digging into the Apple docs to figure out how to solve problems that haven’t been done can be time consuming.
- Error messages can be misleading. Error messages from using Combine and SwiftUI are not always the most readable or the most accurate messages.
We still use UIKit or AppKit for some parts to avoid user experience loss. Swift UI can still be used in UIKit via UIViewRepresentable and UIViewControllerRepresentable. The APIs of UIHostingController is quite constricted. Updating values for and receiving events from SwiftUI in UIKit can be somewhat complex. Luckily, this can be made simpler through using Combine, and optionally, EnvironmentValues.
SwiftUI is Apple’s attempt to create declarative programming. The method is creative by leveraging the declarative programing with existing Swift features, such as generics. Although it is not mature yet, learning SwiftUI is a valuable tool because it is a solution that can better serve both users and developers.
Official Apple Documentation
Swift UI vs UIKit
SwiftUI vs Interface Builder and storyboards
To learn more about innovation at S44, please visit our website.
About the Author:
Oniel Rosario is an iOS Developer. We achieve success by investing in our people and products with focus on innovation and solving complex business challenges.