Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

timer functionality in swift stack overflow

works on swift5.0
var timer = Timer()
var secondsPassed = 0
var totalTime = 300
timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(self.update), userInfo: nil, repeats: true)
@objc func update() {
        if secondsPassed < totalTime{
            secondsPassed += 1     
        }else{
            timer.invalidate()
            print("Time's up")
        }
Comment

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.
    }
}
Comment

count down timer swift stack overflow

var secondsRemaining = 60


Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updateCounter), userInfo: nil, repeats: true)
}
@objc func updateCounter(){
    if secondsRemaining > 0 {
    print("(secondsRemaining) seconds.")
    secondsRemaining -= 1
            }
        }
Comment

timer in swift stack overflow

var timer = NSTimer()
timer(timeInterval: 0.01, target: self, selector: update, userInfo: nil, repeats: false)
Comment

PREVIOUS NEXT
Code Example
Swift :: ios UIButton change image 
Swift :: Swift Trailing Closure 
Swift :: how to show notification icon on tabbar item swift 
Swift :: hstack spacing swiftui 
Swift :: Swift Character Example 
Swift :: how to center vertically scrollview swiftui 
Swift :: uitextfield get focus swift 5 
Swift :: swiftui check available ios 
Swift :: swift subtract dates 
Swift :: swiftui rounded specific corner 
Swift :: two integer variable in swift 
Swift :: how to send a file from file manager in mail swift 
Swift :: swift arkit texture face get position on screen 
Swift :: move view controller to make space for keyboard swift 5 
Swift :: Swift Initializer 
Swift :: how to scroll to section in tableview swift 
Swift :: how to darken view swiftui 
Swift :: Swift Code Reusability 
Swift :: swift get error from the from completion 
Swift :: flow ios swift kotlin 
Swift :: Swift Labeled Statement with break 
Swift :: how to use snippets in xcode 
Swift :: Swift Access Control 
Swift :: swift 5 macos close app 
Swift :: swift search bar 
Ruby :: how to check if data is an array or not ruby 
Ruby :: rails trackable to devise 
Ruby :: ruby print string 
Ruby :: Your Ruby version is 2.7.0, but your Gemfile specified 2.7.1 
Ruby :: rails array include another array 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =