Creating a Tap Counter

Aaron Caines
A free video tutorial from Aaron Caines
iOS 12, Swift 4.2, Objective-C & Xcode 10 Developer
4.4 instructor rating • 19 courses • 37,628 students

Learn more from the full course

The Complete Swift Guide for IOS 8 and Xcode 6

A Guide to iPhone and iPad development. A Complete Xcode 6 and IOS 8 Course with Swift Beginner to pro.

07:24:11 of on-demand video • Updated February 2015

  • Full understanding of Xcode and all it has to offer
  • Learn how to program for IOS 8 to create your own apps
  • Be able to support all devices and screen sizes
  • Full explanation of all objects and functions within IOS development
  • Earn revenue from your apps
  • Start a new career
English [Auto] When you're creating functions applications to make it do something. It's important to consider if you want a additional function to do the opposite of the function you've just added and a great way to show this is with tap. What we're basically going to have is two functions. Our first functions. Every time you press the button it will start counting up in the table in numbers so you press or say one again and then go to two to three to four and so on. And our second function will do the complete opposite to our first one. So instead of putting one every time we press it. Our second function will take away one. Every time we press it. So how we go about creating This is our view here and size it down to the 4.7 for the iPhone 6 to that and then we can add in two buttons. So I simply drag and drop those in to space it out so it fits in our sleeves and copy and paste it to bit time. Now we are secondary but I don't need a label for our results to be displayed and once we complete our action. So I'm going to bring that to the and then censor our text then it may have been the assistant editor and then when the crates are two actions one button and our outlet for our label subdiscipline anybody can get to easy MySpace at night and the actions and the outlet sections are free and can control or drug right click and drag and drag it over and I simply name it label. I mean we need to create some actions for our book and saw some drug that you know at the bottom change it to action. And this will be our pillows one button and one take up the center as we don't need it and then connect that up. I've said what spaced out quickly and I'm a little space here too to add in our second action. And this will be my next one. And again make sure it's on action and take away the sender and connect that up space to our space buttons. I again so we've created our actions now for our buttons one we do quickly is just change the name. So this will be plus one and then this one will be minus one. So it's easy to understand when we come to build and run I can see it to a we can create like an int or a variable. Am actually going to happen we're going to get it to equal to our kind of variable or whatever you want to call it and then Eva plus one or takeaway one depending on what got me press but we already need to have our variable it's already preset on a number. So what we do need to create a variable for us if we do the I O space in the name of it which means simply calling Cantor in Afghanistan and it's simply going to equal zero. So already it's set on zero. So issues are Presti plus one but you should go straight to plus one or if I press the minus one button first you'll go straight to minus one. So it's only pre-sets on 0. And then the functions here how they get it you send plus one every time we press it is simply cancer equals cancer space plus space 1 and semi-coma. So it's basically every time we are available it is going up every time. Now know this is going in the background. I mean it's not being displayed in the label or the label basically not showing us anything at the moment. So we really think it's our kind of the results of our cancer to be displayed within our label. So then if we're going to have the name volleyballs which we call it simply label the text function as that's what we're going to be changing and what we want to do is equal our strength and we do duty to open brackets. And in between it is an equal in the string is our cancer. Very simple. So our label tags people the strength of our cancer and our cancer here is closing in on every time we press it. So to do that to make good Moina something to copy and paste it. And the only thing we are going to change is the kind of creation here of why it's going to do so instead of plus have having simply minus. So again it works the same every time I press a button Oliv. up plus 1 or minus 1 in our countdown. I mean it's all of our counts are whatever is being displayed or whatever the results not counted is printed into our labels text every time pressed the button. So by pressing the action is kind of basically performing two actions. It's the change in accounts and the pain have to cancel text we have in our label so there you go. So we've got our standard function plus we have an alternative opposite function to take it away so it's like you know it's like opposites. So we can do is just change to the iPad iPhone 6 I'm sorry and then go to go in and run and test em again and another is in a simulator. We have two buttons plus one minus one. And then our label. Now our label display no text at the moment as we set our verbal of our counter side of it. So what we could do we could place in the view did loads and loads of our characters displaying face Luzier so we can then simply press our plus one button. So our function here was to add one onto our counter and at the same time adds one to our counter it displays it we've been able to keep going up and up and up and then we can go to a kind of polar opposite function which is the complete opposite to our first function and takes it away. So there you go. All right. All right census 0 0 you start going to the minuses so you can do that up and down. This is a great example of how you can grate your opposite actions or functions to the functions you have. So it's a great way to kind of think about when you develop applications if you want to have this kind of reverse option in your apps. But not only that Creighton's have cancers is brilliant in general applications you can take this one step further and create some useful kind of applications. For example if you was a doorman in a nightclub and you want to make sure you keep track of how many people are coming in and out of the venue it's a brilliant way to have a look. Can't and you can total and tally the amount of people in and out at the end of the night. So it's a brilliant function and it's a brilliant kind of start to the basis of an application.