Get started with SwiftUI right on your iPad
Apple just updated its Swift Playgrounds iPad app with support for Swift 5.1, dark mode, and SwiftUI, which means it’s now possible to try building SwiftUI apps and components entirely on your iPad.
Although Swift Playgrounds comes with a handful of templates for various kinds of projects, none of them are for SwiftUI – at least not yet. Hopefully that will change in the near future, not least because we’re approaching Code Week here in the EU – it would be great to see Apple taking Everyone Can Code to the next level with something based around SwiftUI.
In the meantime, if you want to get started you can create a new Blank Playground then add your code there. It takes a little boilerplate, so to save you some time here’s the code you need to get started:
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
var body: some View {
Text("Hello World")
}
}
PlaygroundPage.current.setLiveView(ContentView())
At this time support for SwiftUI isn’t ideal: NavigationView
doesn’t work well because it tries to run as a split view controller, and there is no support for the instant preview canvas that we get with Xcode – you need to keep tapping “Run My Code”.
Still, it’s a massive leap forward, and is only going to improve. And don’t forget that even without SwiftUI you still get all the benefits of iOS 13, including the new Swift 5.1 opaque return types, Combine, and more.
If you’d like to learn more about how to use SwiftUI to build apps, you should read my free online book: SwiftUI by Example. You might also want to try my 100 Days of SwiftUI course, which teaches you SwiftUI as you build real apps.
SAVE 50% To celebrate WWDC23, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
Link copied to your pasteboard.