我的预览中出现以下错误。
struct DetailView: View {
var header: DataProvider.DataHeader
var body: some View {
Text("...")
}
}
struct DetailView_Previews: PreviewProvider {
var a = DataProvider.DataHeader(title: "a", text: "b")
static var previews: some View {
DetailView(header: a)
}
}
错误是:
Instance member 'a' cannot be used on type 'DetailView_Previews'
为什么会发生这种情况?
这是因为 static var preview
,
所以,既要用静态的,也要用
static var a = DataProvider.DataHeader(title: "a", text: "b")
筑
DetailView(header: DataProvider.DataHeader(title: "a", text: "b"))