From the course: Programming for Non-programmers: iOS 17 and Swift 5

Unlock this course with a free trial

Join today to access over 24,400 courses taught by industry experts.

Enums

Enums

- Our number was pressed method now generally does what we want it to do, and then it displays the proper number up at the top. Now let's shift focus to these mode buttons over here, specifically the addition, subtraction and multiplication buttons. If we want to see which button was pressed, right now we can have the button text be the source of truth on that. So the equal sign or the multiplication sign, and we could do an if, for example like this. You don't have to write this code, you can just look at my screen. If button dot button text is equal to x and then we can write our code right there. The problem with that is that we're using letters and characters for that comparison. And while it would work, what if we wanted to change these buttons to icons instead? Well, then we lose that button text because there's no text inside of the label. So how can we make a good way of knowing exactly which button was pressed, even if we change the UI a little bit? Which we are planning to…

Contents