Swift Playgrounds & SwiftUI: Playground aborts/crashes with VStack/HStack/ZStack

I'm trying to prototype a SwiftUI.View in Swift Playgrounds (iPadOS 14.4.2, no updates pending). All goes well until I get to any kind of stack view.

This is one of those things that could not possibly have passed a unit test, so presumably a configuration exists that doesn't trigger this bug. While I wait for action* on my bug report, can anyone suggest a workaround?

Consider this code. It's meant to produce a red circle with a blue boundary. In an Xcode playground, it does. In Swift Playgrounds, starting from an Xcode Playground (or not) template, the page crashes in various ways. The separate Views display as expected.

Code Block swift
import SwiftUI
import PlaygroundSupport
struct OuterCircle: View {
    var body: some View {
        Circle( )
            .foregroundColor(.blue)
    }
}
struct InnerCircle: View {
    var body: some View {
        Circle( )
            .inset(by: 5.0)
            .foregroundColor(.red)
    }
}
struct StackCircle: View {
    var body: some View {
        ZStack(alignment: .center) {
            OuterCircle()
            InnerCircle()
            // There was a problem encountered while running this playground.
            // Check your code for mistakes.
        }
    }
}
PlaygroundPage.current.setLiveView(
    StackCircle()
        .frame(width: 200, height: 200, alignment: .center)
)


I've tried every permutation of stacking, View-wrapping, and border/stroke/foreground/fill modifiers I can think of. No change, except for the crash message, which may be the message commented in the code, or the like of "Abort() called", or a BSD synchronization timeout. Moving the component Views into an auxiliary source file merely produced the same error message in an alert instead of in-page.

Execution pauses (with a blank canvas) for a few seconds before crashing, and intermediate results do appear in the right margin, so I'd guess this is a runtime thing.

I should file a bug — regardless of my "mistakes," Playgrounds shouldn't crash. In the mean time, though, I'd like to get some value. Can anyone suggest a workaround?

> This question was ostensibly asked and answered at https://developer.apple.com/forums/thread/668268, but the discussion was sidetracked to Xcode and never returned to topic.

Replies

Click on the speedometer button in the bottom left of the canvas and turn off Enable Results.

This seems to be an issue with using SwiftUI in Playgrounds, so when you have errors that have nothing to do with your code make sure that this setting is turned off.

@BabyJ Thanks man. Turn it off really solved the issue.