Adding the variables and background color
Moving into the ContentView
file now, our first task here will be to add a couple of variables and a constant. Let’s start with adding a variable that will bind to the selectedImage
binding property in the ImagePickerView
file.
To do that, we need to create a State
variable, which needs to be the same data type as the selectedImage
variable, a String
type. We can give it the same name as the variable too, selectedImage
, so that you know this variable is bidirectionally linked to the variable in the ImagePickerView
file.
Add this code inside the ContentView
struct, at the top:
@State private var selectedImage: String = "ornament" @State private var shiftColors = false let backgroundColor = Color(.black)
The selectedImage
variable gets set to a String value called ornament
. Next is a variable to track the animation called shiftColors
, which...