7

I have this code, see below, it contains a ForEach loop which is commented out. the same view in an App runs just fine even if the ForEach loop is enabled. However, in a playground it crashes with a very unhelpful error message: "error: Playground execution aborted: error: Execution was interrupted, reason: signal SIGABRT. The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation."

I tried finding information about this message. From what I understand it means that lldb does not know exactly what goes wrong and prints this. So, I turn to stack overflow in the hope someone does know what exactly might by going wrong here....?

import Cocoa
import SwiftUI
import PlaygroundSupport
import Combine

struct RowModel : Identifiable, Hashable {
    var text : String
    var id : UUID = UUID()
}

class My : ObservableObject {
    @Published var s: String  = "Hi there"
    @Published var elements = [
        RowModel(text: "een"),
        RowModel(text: "twee"),
        RowModel(text: "drie"),
        RowModel(text: "vier"),
    ]
}

struct Row : View {
    var item : String
    
    var body : some View {
        Text(item)
    }
}

struct Screen : View {
    @StateObject var my = My()
    var body: some View {
        VStack {
            Text("The screen")
            VStack {
                Row(item: my.elements[0].text)
                Row(item: my.elements[1].text)
//                ForEach(0 ..< my.elements.count, id: \.self){ (index : Int) in
//
//                    Row(item: my.elements[index].text)
//                }
            }.frame(height: 100)
            TextField("enter values", text: $my.s)
        }
    }
}

var view = Screen()
PlaygroundPage.current.setLiveView(view)

Jan
  • 1,582
  • 1
  • 13
  • 19
  • 1
    I think it's a known bug in playground – New Dev Dec 02 '20 at 06:50
  • If this is a known bug it basically means that playgrounds are not ready for swiftUI at all? looks like so basic that a loop should work... why is there even the option to set a swiftUI live view on a playgroundPage if this is a bug? – Jan Dec 02 '20 at 07:12
  • I really don't know... I just encountered it myself recently and found somewhere that said that it was a bug. Not sure if it's recent, will be fixed soon, or whatnot – New Dev Dec 02 '20 at 07:32

2 Answers2

3

I'm late to the party, but this bug is still not fixed at this point so I figured I'd leave this for any future viewer.

This seems to be an issue with results bar on the right, because moving the view to a separate file in Sources (press Command 0) works fine.

Rick
  • 59
  • 5
0

there is a workaround for this bug

move ContentView to a separate file in Sources directory make your models public

more info

https://stackoverflow.com/a/67120969/2027018

ha100
  • 1,563
  • 1
  • 21
  • 28