Invalidating a nstimer
Inside this function, we are going to tell swift that we want to get the value of Swift Counter, add one to the value and then update the label: Run the app and press the play button.The swift timer should start counting up, by one every second. The NSTimer Class comes with a method called invalidate().Click this drop down box and go through the options until you see play, and then select Drag one of these items onto your storyboard from the object library. Once you have done that, head back to the attributed inspector and change the “System Item” to pause.Just like we did with the “play” button: This is going to be our Swift Timer Pause Button: Finally, we are going to drag a UILabel onto the View Controller. I have positioned this in the center and also changed the size using the attributes inspector.
It is all fun and games adding elements to the View Controller but Xcode does not know what to do with them.This method is the only way to remove a timer from an NSRun Loop object.The NSRun Loop object removes its strong reference to the timer, either just before the invalidate method returns or at some later point.Now, we need to create the function that will be called when the Swift Timer app runs the NSTimer().Out of the view Did Load function scope, create another function called update Counter.