Apple's tailored SwiftUI makes coding Mac and iOS apps RAD again

Developing for iGiant's platform just got way easier

Apple's Craig Federighi, Senior VP Software Engineering, introduces SwiftUI at WWDC
Apple's Craig Federighi, Senior VP Software Engineering, introduces SwiftUI at WWDC

WWDC Apple's freshly laid SwiftUI uses a declarative syntax to create user interfaces and enables powerful new visual design tools in Xcode, the company's developer tool for Mac and iOS applications.

SwiftUI was squeezed out at Apple's Worldwide Developer Conference, currently under way in Silicon Valley's San Jose. Craig Federighi, senior VP software engineering, described it as "a new framework built from the ground up to take advantage of everything that Swift had to offer".

The Swift language itself is just five years old, introduced at WWDC 2014 to give developers an alternative to the venerable Objective-C, which dates from the 1980s. Swift is easier to learn and safer to use. There are now more than 450,000 Swift apps in the App Store, Federighi said.

SwiftUI, though, is a huge deal. Instead of building a user interface in code with Apple's UIKit framework, you describe it with declarative statements, adding modifiers to customise how they are rendered. This includes animations and other visual effects.

A declarative framework is not only quicker to code, but also works naturally with visual builders. XCode 11, the new release, includes design tools for constructing a SwiftUI user interface with drag-and-drop, using Inspectors to set properties. A preview shows what your application will look like, and you can also push the preview instantly to an iPhone or other device for testing there.

Composing a user interface with Xcode 11 and SwiftUI

Composing a user interface with Xcode 11 and SwiftUI

These new XCode tools support two-way design. In other words, you can manipulate the UI in the visual design and it will update the code, and vice versa.

When you build with SwiftUI, there's built-in support for a number of significant features including accessibility, localisation, right-to-left languages and the new Dark Mode.

There is also integration with UIKit. You can place UIKit views and view controllers inside SwiftUI views and vice versa.

SwiftUI will build applications for all Apple's platforms: iOS, macOS, tvOS and watchOS. It requires new versions of these operating systems, for example iOS 13.0 or higher, which are available in beta today and scheduled to be with the general public in Autumn 2019.

Xcode will support all these platforms in a single project, while still allowing you to optimise the layout for each different form factor. You can also bring an existing iPad app to the Mac by adding SwiftUI code.

There is support for conditional compilation via #if directives, so you can add special code for debugging or other scenarios.

The combination of Swift and SwiftUI gives Apple a first-party development platform that offers Rapid Application Development (RAD) without sacrificing native performance. Observers like Steven Sinofsky, formerly Microsoft's Windows chief, were quick to show their enthusiasm.

This is despite the fact Apple is catching up to what has been offered on other platforms for years. "Apple's new SwiftUI looks so much like the @ApacheGroovy venerable 15-yo Swing Builder," remarked Guillaume Laforge, Developer Advocate for Google Cloud and co-founder of ApacheGroovy.

Microsoft uses the XAML language for a declarative UI framework for Windows Presentation Foundation, and the cross-platform Xamarin tools use a different flavour of XAML for Xamarin Forms.

Google's cross-platform Flutter project also looks superficially similar to SwiftUI, though the language of Flutter is Dart.

Presuming SwiftUI is as good as it looks at first glance, these alternative approaches to building applications for Apple's platform may fall by the wayside as the native tools will be equally productive and won't suffer from any cross-platform compromises. ®




Biting the hand that feeds IT © 1998–2019