Sam
Sam

Reputation: 21

Why we can not pass instance variable in swiftUI Priview?

I am using swift UI code as below

struct ABC_Previews: PreviewProvider {
    @Binding var boolVar :  Bool
    static var previews: some View {
        FilterDeviceList(isCloseView: isCloseView)
    }
}

But its throwing error like "Instance member 'boolVar' cannot be used on type 'ABC_Previews' "

Upvotes: 1

Views: 360

Answers (1)

Asperi
Asperi

Reputation: 257779

Because previews is static, ie type-wide

You can use something like

static var previews: some View {
    FilterDeviceList(isCloseView: .constant(true)) // if binding is expected
}

Upvotes: 3

Related Questions