Adding the Binding variable and images
Okay, let’s get started. So, create a new Xcode project, give it a name, and we will get underway.
We will start by adding a new SwiftUI file to the project, which I’ll call ImagePickerView (you should be very familiar with the process of adding new files as you've done it several times now). Then within the struct, add a variable called selectedImage
, and make it of the String
type. We will prefix this variable with the @Binding wrapper, as shown here:
struct ImagePickerView: View { @Binding var selectedImage: String var body: some View { Text("Hello World") } }
The @Binding
property wrapper is used to create a two-way binding between a source of truth (for example, a state property in a parent view) and a view that depends on that state. This ImagePickerView
is the source of truth...