Group Group Group Group Group Group Group Group Group

SwiftUI: Getting Started |


In this SwiftUI tutorial, you’ll learn how to layout the UI by declaring and modifying views, and how to use state variables to update your UI. You’ll use Xcode’s new preview and live preview, and experience the joy of code and WYSIWYG layout that stay in sync.

This is a companion discussion topic for the original entry at

Nice post. Wondering about how one would implement UI testing for the UI built with SwiftUI? or can we do a Unit testing of it?


The Testing in Xcode WWDC session demoed unit and UI testing of a SwiftUI app. I had a quick look and the test code doesn’t look too different.


Slightly confusing going from this step:

VStack {
HStack {
Text(“Target Color Block”)
Text(“Guess Color Block”)

Text(“Hit me button”)

VStack {
Text(“Red slider”)
Text(“Green slider”)
Text(“Blue slider”)

To this step

HStack {
// Target color block
VStack {
Text(“Match this color”)
// Guess color block
VStack {
HStack {
Text(“R: xxx”)
Text(“G: xxx”)
Text(“B: xxx”)

Everything becomes magically wrapped in an HStack


I leave it up to you, how you want to do this: one way is to embed each of the 2 Text placeholders in a VStack, then modify each Stack to contain a Rectangle and one or 3 Text views.

The HStack containing the 2 color block Text placeholders was already there.

1 Like

Is there any chance to try SwiftUI with Mojave 10.14.5 and Xcode 10.2.1?


you can build and run SwiftUI apps in Xcode 11 beta on Mojave 10.14.5 — you just won’t see the previews; you’ll have to run in the simulator to see your UI

the tutorial has a link to Apple’s instructions for installing Catalina on a volume (not partition), so you don’t have to allocate a specific amount of space for it, and you can delete the volume when you don’t need it anymore. Scroll down to see the instructions for switching between Catalina an Mojave — I found these more reliable than holding down the Option key when restarting.


At the end of the tutorial you show landscape preview in a simulator. Do you know how to test for device rotation in SwiftUI?


sorry, I don’t know … have you tried UIKit’s UIDeviceOrientation, to see if it works with SwiftUI?

I just noticed SceneDelegate.swift imports UIKit, so that might be somewhere you can test for orientation?


You can get size classes from Environment, which is the preferred way even in UIKit. If you absolutely need device orientation, you could grab it in SceneDelegate and insert it into the Environment so your SwiftUI code can retrieve it.

// @audrey