SwiftUI Xcode näkymä

SwiftUI – Ready for Developers 2021?

Hannu Alakangas, 14/06/2021

Roughly a year ago we released an article series about programming languages in the Finnish mobile development scene. You can read all of the previous articles (in Finnish only) by clicking:

Now that the 2021 WWDC developer conference is in full steam, we would like to provide you with an overview into possibly the hottest topic in the Apple developer world: SwiftUI. Our Swift developers already have a couple of real-world SwiftUI client projects under their belts.

SwiftUI Xcode näkymä

SwiftUI is a UI implementation framework that brings with it a reactive framework and a new visual UI design tool (Xcode preview). The latter provides developers with a real-time view into how code changes affect the UI, thus there is no need to compile the application repeatedly to review the UI.

The first version of SwiftUI was launched together with iOS 13, unfortunately it was nowhere near production-ready. iOS 14 made the use of SwiftUI in real-world applications feasible, thanks to increased stability and new features. iOS 15 improves the situation even further.

After a developer understands how SwiftUI works, view creation takes considerably less time than previously. The aforementioned Xcode preview needs more affectionate care to improve, e.g., error management, but the situation is already pretty good. One of the challenges relates to the fact that the preview may in some cases provide the user with an error message, without any error log. This means that in order to get a meaningful log file, the developer needs to launch the application in a simulator. Additionally, the preview and Xcode get stuck in an error situation, although there are no errors. The only solution is usually to restart Xcode.

Combine framework

SwiftUI comes with another framework, called Combine. Combine is responsible for all reactive functionalities. Under the bonnet, the largest difference, when compared with the previous way of thinking relates to managing variables and the application state. Here, SwiftUI uses a so-called declarative approach, which makes accessing application state information and variables extremely easy. These improvements make the development process significantly more efficient and relaying data between views becomes effortless.

Of all the Combine features, our favourite is the possibility to use environment objects (EnvironmentObject). Such variables, when declared at a top level, are automatically inherited by the lower levels, and even their sub-levels. Additionally, these variables can be accessed by every view, which makes sharing data between views easier than before.

Our opinion

This is the future of iOS application development. Period. SwiftUI is ready for production, when the minimum operating system level is iOS 14. Furthermore, as the tool constantly gets more and more updates, there are no reasons not to use SwiftUI in all new application projects. Generally, the whole work process is considerably faster when compared with older tools. Even though there still are some things that cannot be created with SwiftUI, all situations can be solved by using UIKit wrappers.