用 ForEach 撞毁游乐场 [英] crashing playground with ForEach

查看:29
本文介绍了用 ForEach 撞毁游乐场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码,见下文,它包含一个被注释掉的 ForEach 循环.即使启用了 ForEach 循环,应用程序中的相同视图也能正常运行.但是,在操场上它会崩溃并显示一条非常无用的错误消息:"错误:操场执行中止:错误:执行被中断,原因:信号SIGABRT.进程一直停留在它被中断的地方,使用线程返回 -x";返回到表达式求值前的状态."

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."

我尝试查找有关此邮件的信息.据我了解,这意味着 lldb 并不确切知道出了什么问题并打印出来.所以,我转向堆栈溢出,希望有人确实知道这里出了什么问题......?

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)

推荐答案

我迟到了,但这个错误目前还没有修复,所以我想我会把这个留给未来的观众.

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.

>

这似乎是右侧结果栏的问题,因为将视图移动到 Sources 中的单独文件(按 Command 0)工作正常.

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.

这篇关于用 ForEach 撞毁游乐场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆