SwiftUI. How To pass Binding variable to PreviewProvider

Hi, this is a short How-To to give you an example on how to pass Binding<> variable to PreviewProvider.

Let’s assume you have a SwiftUI view with the Binding variable, that looks something like this:

In order to pass a Binding variable to ExampleView’s constructor in PreviewProvider you need to do the following:

JFY, you can wrap anything, depending of what type of Binding variable you have. For example:

and PreviewProvider:

That’s it. Happy coding!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store