What is SwiftUI?
The recently released iOS 13 came with a new framework, SwiftUI. In this article, I’ll focus on the differences between SwiftUI and UIKit.
SwiftUI is a new and constructive method of creating interfaces across all Apple platforms. In fact, you will now be able to create user interfaces for all Apple devices with one set of tools and APIs. The new and improved Swift syntax allows you to write the code with greater ease, and it will work seamlessly with all of the Xcode design tools.
SwiftUI was created for cross-platform use to build applications with less code than UIKit but with the same complexity.
SwiftUI framework offers the following benefits:
- Declarative syntax : This means that all you will have to do is tell the UI what you would like it to do. For example, you can write that you want several text fields and then enter all of the finer details, such as the font and alignment of each field.
- Design tools : A lot of work went into making the coding process easier for developers. One of the interesting SwiftUI components is the design canvas. During the coding process, all changes that you make are synchronised with the code in the adjacent editor. Also, all of the code that you enter will be visible as a preview right away. This makes programming custom mobile app simpler and easier.
- Native on all Apple platforms : Apple has a lot of experience in creating innovative products, and this is certainly evident when we look at SwiftUI. All of the Apple-specific experiences that the users enjoy will be present in the code that you create with SwiftUI, and all of your apps will have direct access to the technology of each platform.
- It offers Live Preview. This is a very convenient and progressive way to see the results of code execution in real time without having to build. I’m not sure if it somehow affects the processor. So far, I’ve noticed a delay provoked by the use of Live Preview, but I think Apple will soon make improvements.
- There’s no AutoLayout or related problems. Instead, you use things like HStack, VStack, ZStack, Groups, Lists, and more. Unlike AutoLayout, SwiftUI always produces a valid layout. There’s no such thing as an ambiguous or unsatisfiable layout. SwiftUI replaces storyboards with code, making it easy to create a reusable view and avoid conflicts related with the simultaneous use of one project by the development team.
The negatives of SwiftUI are:
- It supports only iOS 13 and Xcode 11. By switching to them, you abandon users of older versions of iOS, which is a radical move devoid of concern for the user. But since Apple annually updates its list of supported iOS versions, I think SwiftUI will be used more over the next two years as users install the latest iOS version.
- It’s still very young, so there isn’t much data on Stack Overflow. This means that you can’t get much help resolving complicated issues.
- It doesn’t allow you to examine the view hierarchy in Xcode Previews.