I am new to Xcode 12.4/Playgrounds, and am trying to get this code to run. So far, it doesn't generate the View object, and does not generate an error code either. Any ideas about what I'm doing wrong?
import SwiftUI
import PlaygroundSupport
struct ExampleView: View{
var body: some View {
VStack {
Rectangle()
.fill(Color.blue)
.frame(width:200, height:200)
Button(action: {
})
Text("Rotate")
}
};.padding(10)
}
PlaygroundPage.current.setLiveView(Example-View())
.padding(100)
Playgrounds is still kind of buggy (it's been so many years already)... anyway, you have a couple of errors:
Missing argument for parameter #1 in call
: you're missing brackets{}
after theButton
that define what it looks likeExpected declaration
: Modifiers like.padding()
need to be inside thevar body: some View
. Move it to right after theVStack
instead.Cannot find 'Example' in scope
: You misspelledExampleView
.padding()
toPlaygroundPage.current.setLiveView(ExampleView())
. Modifiers always need to be inside aView
.Here's the fixed code:
Result: