我尝试与pisteData.json数据文件一起预览构建此代码,并且可以正常构建,但由于“无法预览此文件-[应用名称]可能崩溃”而崩溃,
import SwiftUI
struct PisteRow: View {
var pista: Structure
var body: some View {
HStack {
padding()
pista.image
.resizable()
.frame(width: 50, height: 50)
.clipShape(Circle())
Text(pista.name)
Spacer()
}
}
}
struct PisteRow_Previews: PreviewProvider {
static var previews: some View {
PisteRow(pista: pisteData[0])
.previewLayout(.fixed(width: 300, height: 70))
}
}
答案 0 :(得分:0)
您可以在预览中使用.init()函数来初始化测试Structure
。像这样:
struct PisteRow_Previews: PreviewProvider {
static var previews: some View {
PisteRow(pista: .init(image: Image(systemName:"xmark"), text: "test"))
.previewLayout(.fixed(width: 300, height: 70))
}
}