WWDC22 SALE: 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?

   

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

   

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.

   

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)

   

Save 50% in my Black Friday sale.

SAVE 50% To celebrate WWDC22, 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.

Save 50% on all our books and bundles!

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

Reply to this topic…

You need to create an account or log in to reply.

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.