GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

SOLVED: SwiftUI in Playgrounds

Forums > SwiftUI

I'm really confused about the whole Playground workflow. I have an iPad, when I create a playground, it is SwiftUI only. But then when I create a Playground in Xcode on my Mac, it is only UIKit. Is it possible to create a SwiftUI playground via Xcode on the Mac?

2      

I get a SwiftUI playground when I make one from my mac and I thought it was always like that

2      

When you create a new Playground in Xcode, you can choose the template as either iOS or macOS. The option is in the top left corner.

Then you choose the type of Playground - Blank, Game, … which will set up the Playground with any necessary imports and base code.

2      

I found my answer on this page

So I created an iOS SingleView playground and replaced the generated code with this:

import SwiftUI
import PlaygroundSupport

struct ContentView: View {
    var body: some View {
        VStack {
            Text("Hello, World!")
            Spacer()
            Text("Goodbye, World!")
        }
    }
}

let view = ContentView()
PlaygroundPage.current.setLiveView(view)

3      

Hacking with Swift is sponsored by Alex.

SPONSORED Alex is the iOS & Mac developer’s ultimate AI assistant. It integrates with Xcode, offering a best-in-class Swift coding agent. Generate modern SwiftUI from images. Fast-apply suggestions from Claude 3.5 Sonnet, o3-mini, and DeepSeek R1. Autofix Swift 6 errors and warnings. And so much more. Start your 7-day free trial today!

Try for free!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.