Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

crashing playground with ForEach

Tags:

swiftui

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)

like image 784
Jan Avatar asked Dec 02 '20 06:12

Jan


1 Answers

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.

like image 154
Rick Avatar answered Nov 13 '22 15:11

Rick