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.
Handling the numeric button presses
From the course: Programming for Non-programmers: iOS 17 and Swift 5
Handling the numeric button presses
- [Instructor] In my content view, anytime I press a button, that button shows up in the total text view. However, in a real calculator, pressing a four, for example, if we have a three right here would result in seeing 34. And our calculator shows a four. So let's look at how to append those numbers onto the previous number. Go over to button grid and then you want to find the number was pressed method and that's where we're going to be working. So what we need to do is take the existing total value and append to it button.buttonText. Fortunately that's a pretty simple operation. I'm going to create an extra space before button.buttonText, and then I'm going to type total, a space, and a plus sign. So this plus is not used for a mathematical operation, rather it's used for string concatenation. It takes this string total and then appends to it whatever button text is. So let's take a look at how that works over in content view. So start pressing numbers, and it pretty much works as…
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)
-
-