Setting up the project and adding a Binding variable
Okay, let’s get started! As always, we’ll create a new Xcode project (I’m going to call mine Elevator
).
Next, in the GitHub repo, take all the images from the Chapter 11
folder and drop them into the Asset Catalog. These images include doorDrame
, leftDoor
, rightDoor
, inside
, man
, man2
, man3
, and man4
.
Then, drop the audio files – doorsOpenClose
and elevatorChime
– into the Project Navigator.
Next, we’re going to need a new file where we can assemble the elevator and add the people, so create a new SwiftUI View file and call it ElevatorAndPeopleView
. We only need one variable in this file, which will be the Binding variable. Let’s add it at the top, inside the ElevatorAndPeopleView
struct:
@Binding var doorsOpened: Bool
This variable will control the elevator doors opening and closing.
Let’s update the Previews
so that the code will build...