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
From the course: Programming for Non-programmers: iOS 17 and Swift 5
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Understanding conditional statements4m 21s
-
(Locked)
Using conditional statements and Booleans4m 50s
-
(Locked)
Handling the numeric button presses4m 45s
-
(Locked)
Optionals and If Let statements3m
-
(Locked)
Enums5m 4s
-
(Locked)
Challenge: Conditionals2m 49s
-
(Locked)
Solution: Conditionals1m 51s
-
(Locked)
-
-