nickcoding
nickcoding

Reputation: 475

Passing a class instance into a PreviewProvider in SwiftUI?

so in my ContentView, I'm creating a view with:

ViewName(variable: ObservedObjectInstance)

where variable is the name of an initialization parameter required for the view; it takes in something of the same type as the ObservedObjectInstance. The ObservedObjectInstance is an @ObservedObject variable that was declared as a struct-level variable. In the ViewName class, I'd like to be able to access ObservedObjectInstance but I'm not sure how. I tried just declaring the following as a struct-level variable:

var variable: ObservedObjectClassType

and then in the PreviewProvider, I tried doing the following:

ViewName(variable: variable)

but it didn't work. I'm pretty sure the declaration of 'variable' in the ViewName class and the PreviewProvider is what's wrong, but I'm not sure how to fix it. Any help would be greatly appreciated.

Upvotes: 1

Views: 541

Answers (1)

Asperi
Asperi

Reputation: 257693

In PreviewProvider use the following

ViewName(variable: ObservedObjectClassType())

Upvotes: 1

Related Questions