Following error in my preview:
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) } }
Error is:
Instance member 'a' cannot be used on type 'DetailView_Previews'
Why this is happening?
Unless otherwise specified, a member declared within a class is an instance member. So instanceInteger and instanceMethod are both instance members. The runtime system creates one copy of each instance variable for each instance of a class created by a program.
Instance Variable cannot have a Static modifier as it will become a Class level variable. Meaning STATIC is one of the keyword which cannot be used with Instance variable.
It is due to static var preview
,
so use either static as well
static var a = DataProvider.DataHeader(title: "a", text: "b")
or construct in place
DetailView(header: DataProvider.DataHeader(title: "a", text: "b"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With