我有这个代码,见下文,它包含一个被注释掉的 ForEach 循环。即使启用了 ForEach 循环,应用程序中的相同视图也能正常运行。但是,在操场上它会崩溃并显示一条非常无用的错误消息:“错误:操场执行中止:错误:执行被中断,原因:信号 SIGABRT。进程已留在中断处,使用“线程返回 - x" 返回到表达式求值前的状态。"
我尝试查找有关此消息的信息。据我了解,这意味着 lldb 并不确切知道出了什么问题并打印出来。所以,我转向堆栈溢出,希望有人知道这里出了什么问题......?
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)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
341 次 |
最近记录: |