Join Todd Perkins for an in-depth discussion in this video Setting the calculator to add or subtract, part of Programming for Non-Programmers with iOS 9 and Swift.
- When the user taps the plus or the minus button,…there are a few things that we want to happen.…First, we want the calculator to change modes.…So, it's either going to be in addition mode…or subtraction mode, when the plus…or the minus button is tapped.…But we also want to save the number…that was entered into the calculator…before that button was pressed.…For example, the user taps a one on the calculator,…and they're going to add something to the number one.…So after that they tap the plus button.…We're going to keep that one on the screen…and save it in the background.…
When the user taps a two to add two to one,…a two then shows up on the calculator,…not a 12, just a two, and that one…is then stored in the background.…So when the user taps the equals button,…two is then added to the number…that's saved in the background…through the savedNum variable.…So let's look at how that works.…I'll go inside a tappedPlus, and all we're…going to do in here is call changeMode,…passing in modes.ADDITION.…
I'll do the same thing for tappedMinus,…
Author
Updated
10/24/2016Released
12/7/2015If you find you'd like to learn more, see iOS App Development Essential Training, Foundations of Programming: Fundamentals, or any of the other programming courses in our library.
- Installing Xcode
- Creating an Xcode project
- Configuring the iOS Simulator
- Understanding variables
- Connecting visual objects to variables
- Understanding functions, methods, and selectors
- Connecting a button to a method
- Using conditional statements
- Setting up the user interface
- Connecting code elements to build an app
Skill Level Beginner
Duration
Views
Related Courses
-
Introduction
-
Welcome39s
-
Using the exercise files2m 2s
-
-
1. Setting Up Your Coding Environment
-
Swift 2 in Xcode 81m 14s
-
2. Programming Building Blocks: Variables
-
Understanding variables3m 2s
-
Using instance variables7m 1s
-
3. Programming Building Blocks: Methods
-
Understanding methods4m 19s
-
Using methods9m 3s
-
-
4. Programming Building Blocks: Conditional Statements
-
Using conditional statements4m 35s
-
5. Building Your First Full Application
-
Setting up the user interface12m 20s
-
Conclusion
-
Next steps41s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Setting the calculator to add or subtract