Adding the data model functions
In this section, we will create five functions, and each one oversees a specific task:
- A function to open and close the doors
- A function to play the chimes bell sound that signifies the elevator has reached its destination
- A function to play the door opening and closing sounds
- A function to light up the floor indicator lights
- A function to stop all the timers
Let’s start by creating the function that will open and close the doors.
Adding the doorOpenTimer function
Come back into the DataModel
class, and directly underneath the last variable, add the following function:
func openDoors() { doorOpenTimer = Timer.scheduledTimer(withTimeInterval: 8, repeats: false) { _ in self.doorsOpened.toggle() } }
This function is called openDoors...