It will display them when you run the swift timer project in the simulator but try clicking any of them. So, no we need to make sure Xcode knows what we are going to do with them.In your View Controller.swift file, inside the class Declaration Scope type: Head back over to your Main.Inside this code there are a few things that we have written in capitals; TIME_INCREMENT, FUNCTION, BOOL. Here is what they do: What we have done here is told the NSTimer() that we are going to run this every 1 second.
Simply search for the elements and drag them onto the View Controller.Drag this element onto your View Controller and place it at the bottom, like so: This Toolbar already has one item (button) on it called: Item. Now, in the Attributes Inspector, There is a drop down box next to the title: “System Item”.You should see a View Did Load func in your View Controller. Inside this function we are going to get the value of the Swift Counter variable that we just set, convert it to a string and then make it show in the label counting Label.If you manually change the value of Swift Counter and run your app. That’s great, it means Xcode knows what the variables are and that they are supposed to update.Now let’s make it so that this Swift Timer app actually counts the number for us.
Inside the IBAction that we created for the Start Button, write: What this code does is first assigns a new instance of NSTimer() to the Variable Swift Timer that we initiated earlier.The NSTimer class can be used to create swift timer objects in your i OS applications. I’m sure you’ve all seen i OS applications that have a similar function to this. Upon firing it will send a specified message to your swift app target object. Well, it works by waiting for a specific interval of time to elapse before it fires.For example you can tell your NSTimer object to send a message to a window with instructions to perform an update after a period of time has elapsed, or with this example update a label every second.So now, are you wondering how to use NSTimer in Swift? I’m about to show you in this swift timer tutorial.Storyboard, We are now going to link up these Swift Timer Elements.