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

Unlock this course with a free trial

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

Storing the saved number

Storing the saved number

"

- [Instructor] In this chapter we're going to finish our calculator. What we need to do to do that is to be able to perform mathematical operations on two sets of numbers. The number that you press before you press the mathematical operator button, and the number that you press after. To do that, we need to have two new variables. One representing the value before the operator button was pressed, and then one representing the current value that's showing in the calculator. So let's scroll all the way up to the top of ButtonGrid, and then below our state variables, we're going to create two more state variables. Remember, state variables need the state flag to say that they're able to be changed at runtime. So @State, capital S. var savedInt. This will represent the number before pressing the mode or mathematical operator button. We'll initialize that to zero. Go to the next line, create another State var, and we're going to call this currentInt. So this is going to be the integer…

Inhalt