how do i have countdown timer in swift stackoverflow
@IBAction func start(sender: UIButton) {
self.timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(ViewController.update(_:)), userInfo: nil, repeats: true)
NSRunLoop.currentRunLoop().addTimer(self.timer, forMode: NSRunLoopCommonModes)
startTime = NSDate() // new instance variable that you would need to add.
}
func update() {
let elapsedTime = NSDate().timeIntervalSinceDate(startTime)
let currTime = totalTime - elapsedTime
//total time is an instance variable that is the total amount of time in seconds that you want
countDown.text = String(currTime)
if currTime < 0 {
timer.invalidate()
//do other stuff that you need to do when time runs out.
}
}
Also in Swift:
- swift uiview add tap gesture
- foreach swift
- swift xcode debug cannot see code backtrace
- loop backwards swift
- blur background swiftui
- swift assign tuple to variables
- swift change background color
- ios swift convert int to string
- guard let swift
- number of characters in a string swift
- register page
- swift get slected row data in tableview cell
- swift get current hour
- swift change navigation bar color
- swift pop to specific view controller
- swift has Top Notch
- go to view controller programmatically swift
- get icloud doc swift
- view will appear
- swift 5 only the day number from date
- how do i have countdown timer in swift stackoverflow
- swift animate a label ishidden
- add to beginning of array swift
- swipe right to delete swiftui