Animating an Elevator
Welcome to the elevator project! In this one, we’re going to create a working elevator, complete with sounds, floor lights, a button, and even some images of people inside. We will control the elevator using timers that are available from the Swift timer class, as we have done in previous projects.
To bring these elements together, we’ll create a data model using the @ObservableObject
protocol. Apple recommends making a data model as the place to store and process the data that the application uses. The data model is also separate from the app’s user interface, where the views are created. The reason to keep data and the UI separate is that this paradigm fosters modularity and testability. It’s easier to find bugs in your logic when the data is not mixed in with UI code. Once we have the data model set up, we can then publish that data anywhere in the app using publishing wrappers, as we will see later.
In this chapter, we will...