BLACK FRIDAY: Save 50% on all my Swift books and bundles! >>

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      

Save 50% in my WWDC sale.

SAVE 50% All our books and bundles are half price for Black Friday, 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.

Save 50% on all our books and bundles!

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.