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,800 courses taught by industry experts.
Solution: Conditionals
From the course: Programming for Non-programmers: iOS 17 and Swift 5
Solution: Conditionals
- [Instructor] Here is a solution to the challenge. Since the criteria for the challenge were pretty specific, your code might look pretty similar to mine this time around, but that's okay if it's not. Let's go up to the top inside of button grid and I'm going to create a new state variable. Remember, we're creating a state variable because it's a value we're changing at runtime. So state var, and we'll call this last button was mode and I'm just going to set that equal to false. So that was the first step that we needed to do. Now what we need to do is go down to the mode was pressed method, and then I'm going to replace the print statement with last button was mode equals true. I mentioned to put this at the top, but it's okay if it's at the bottom, as well. For what we're doing, it doesn't make a difference. In the number was pressed method, let's use an if statement to see if the last button was mode. If last button was mode, then some curly braces, we set last button was mode…
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)
-
-