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

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…

Contents