Apple made a huge announcement at WWDC, revealing a brand-new way of building user interfaces called SwiftUI.
SwiftUI is a new framework that allows you to design and develop user interfaces declaratively and with less code. Unlike UIKit, which is commonly used in conjunction with storyboards, SwiftUI is completely software-based. However, SwiftUI syntax is very easy to understand.
SwiftUI is a different way to set Auto Layout-like constraints, it’s not a separate tool or a separate technology, but it’s a fresh and new concept.
- UI can be developed faster: Developing your UI is significantly faster-even faster than using Storyboards. Between the visual previews that are provided and the speed at which you can preview your work in Xcode, this can significantly speed up the amount of time spent iterating on how your UI behaves.
- Code is simple and easy: The code is simple and clean. It’s very easy to understand.
- App crashing is minimal: The app will no longer crash if you forget to update the @IBOutlet association with the variable.
- Dark mode: Developers can easily add dark mode to their apps and set it as the default theme, and users can easily enable dark mode.
- SwiftUI offers Live Preview: This is a very progressive and convenient way for the developers to see the results of code execution in real time without having to build.
- SwiftUI replaces storyboards with code: It replaces storyboards making it easy to create a reusable view and avoid conflicts related with the simultaneous use of one project by the development team.
- Supports only iOS 13 – Xcode 11 and higher: SwiftUI is supported in iOS 13-Xcode 11 or higher only. It doesn’t work for the lower versions of iOS which is probably the negative aspect of SwiftUI.
- More complex tasks don’t have good example code yet: As SwiftUI is the latest framework, you won’t find many complex examples/problems in a stack overflow. You might have to read the Apple docs and figure out how to put together multiple pieces that have never been written about before.
- Error messages can be misleading/not accurate: Error messages from using Combine and SwiftUI are not the most accurate messages.
SWIFTUI REAL TIME EXAMPLE: