UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

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.