Build a SwiftUI view in Swift Playgrounds
Show Apple's description.
Easily prototype and play around with SwiftUI views when you use them with Swift Playgrounds. We’ll show you how to build a SwiftUI view in a Xcode-compatible playground, and explore tools to help you easily edit and preview your code. For more on Swift Playgrounds, check out our interactive challenge, “Swan's Quest”, and learn to build your own by watching “Create Swift Playgrounds Content for iPad and Mac”.
Creating an Xcode-compatible Playground (from the Swift Playgrounds app)
From main app screen:
See Allbutton in the bottom right hand corner of the screen.
- scroll to the end of the
Showing a SwiftUI live view
After opening a playground:
- import the
PlaygroundSupportframework, which lets us customize the behavior of the playground, including showing live views
- set the playground live view with the your view /
- tap the
Run my Codebutton in the bottom right of the screen to show the live view.