Timer Updating Label 1 Second Behind 2nd Timer Counting Down Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!NSTimer timestamp timeinterval questionIncreasing an images size over time?Why don't use var at the beginning?NSTimer questions (closure, @objc, and etc.)Swift 2 iOS 9 animation disappears after button text changedNSTimer ConfusionSending an NSTimer target message to a different class; extracting its userInfo parameterAdding a custom UIViewcontroller to subview programmatically but getting an error message “Cannot convert value of type…”Timer doesn't work properly swiftHow to optimize UITableViewCell, because my UITableView lags

What to do with someone that cheated their way through university and a PhD program?

Password Generator in batch

Need of separate security plugins for both root and subfolder sites Wordpress?

Trumpet valves, lengths, and pitch

I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?

Raising a bilingual kid. When should we introduce the majority language?

Expansion//Explosion and Siren Stormtamer

Protagonist's race is hidden - should I reveal it?

Why did Israel vote against lifting the American embargo on Cuba?

Is Bran literally the world's memory?

Is Electric Central Heating worth it if using Solar Panels?

Mistake in years of experience in resume?

A Paper Record is What I Hamper

What is the term for a person whose job is to place products on shelves in stores?

Suing a Police Officer Instead of the Police Department

std::is_constructible on incomplete types

Additive group of local rings

Has a Nobel Peace laureate ever been accused of war crimes?

"Whatever a Russian does, they end up making the Kalashnikov gun"? Are there any similar proverbs in English?

Book with legacy programming code on a space ship that the main character hacks to escape

Identify story/novel: Tribe on colonized planet, not aware of this. "Taboo," altitude sickness, robot guardian (60s? Young Adult?)

Does Feeblemind produce an ongoing magical effect that can be dispelled?

How to translate "red flag" into Spanish?

How to get even lighting when using flash for group photos near wall?



Timer Updating Label 1 Second Behind 2nd Timer Counting Down



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!NSTimer timestamp timeinterval questionIncreasing an images size over time?Why don't use var at the beginning?NSTimer questions (closure, @objc, and etc.)Swift 2 iOS 9 animation disappears after button text changedNSTimer ConfusionSending an NSTimer target message to a different class; extracting its userInfo parameterAdding a custom UIViewcontroller to subview programmatically but getting an error message “Cannot convert value of type…”Timer doesn't work properly swiftHow to optimize UITableViewCell, because my UITableView lags



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm having difficulties attempting to link two timers together. I'm trying to have a timer count down from a specified amount and to have a second timer constantly updating a label on a view controller. However, I end up having the timer that updates the label lagging exactly 1 second behind the first timer in the timer class. Here's what I have for the view controller: (note that this is a condensed version of my code)



class HomeViewController: UIViewController 
@IBOutlet var timeLabel: UILabel!

override func viewDidLoad()
timeLabel.text = account.deedManager.globalTimer.timerStr

Timer.scheduledTimer(timeInterval: 0.05, target: self, selector: #selector(UpdateTime), userInfo: nil, repeats: true)


@objc func UpdateTime()
self.timeLabel.text = account.deedManager.globalTimer.timerStr




And here is the Timer class:



class TimerModel: NSObject, NSCoding 
var myTimer: Timer? = Timer()
var timerInterval: TimeInterval = 1.0
var timerEnd: TimeInterval = 0.0
var timerCount: TimeInterval = 86400.0 // 24 hours
var timerStr: String = "TIME"

func StartTimer(time: Double)
timerCount = time
myTimer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(UpdateTime), userInfo: nil, repeats: true)


@objc func UpdateTime()
self.timerStr = self.TimerDate(time: self.timerCount)
self.timerCount-=1
print(self.timerStr)


func TimerDate(time:TimeInterval) -> String
let hours = Int(time) / 3600
let minutes = Int(time) / 60 % 60
let seconds = Int(time) % 60
return String(format: "%02i:%02i:%02i", hours, minutes, seconds)




I've tried to make the first timer a 0.05 interval so that it updates more rapidly than the timer class, but it lags behind exactly a second no matter what interval I put it at. I don't want to put the count down timer inside the view controller as I want the timer global for all view controllers. If you have any ideas, let me know.










share|improve this question






























    0















    I'm having difficulties attempting to link two timers together. I'm trying to have a timer count down from a specified amount and to have a second timer constantly updating a label on a view controller. However, I end up having the timer that updates the label lagging exactly 1 second behind the first timer in the timer class. Here's what I have for the view controller: (note that this is a condensed version of my code)



    class HomeViewController: UIViewController 
    @IBOutlet var timeLabel: UILabel!

    override func viewDidLoad()
    timeLabel.text = account.deedManager.globalTimer.timerStr

    Timer.scheduledTimer(timeInterval: 0.05, target: self, selector: #selector(UpdateTime), userInfo: nil, repeats: true)


    @objc func UpdateTime()
    self.timeLabel.text = account.deedManager.globalTimer.timerStr




    And here is the Timer class:



    class TimerModel: NSObject, NSCoding 
    var myTimer: Timer? = Timer()
    var timerInterval: TimeInterval = 1.0
    var timerEnd: TimeInterval = 0.0
    var timerCount: TimeInterval = 86400.0 // 24 hours
    var timerStr: String = "TIME"

    func StartTimer(time: Double)
    timerCount = time
    myTimer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(UpdateTime), userInfo: nil, repeats: true)


    @objc func UpdateTime()
    self.timerStr = self.TimerDate(time: self.timerCount)
    self.timerCount-=1
    print(self.timerStr)


    func TimerDate(time:TimeInterval) -> String
    let hours = Int(time) / 3600
    let minutes = Int(time) / 60 % 60
    let seconds = Int(time) % 60
    return String(format: "%02i:%02i:%02i", hours, minutes, seconds)




    I've tried to make the first timer a 0.05 interval so that it updates more rapidly than the timer class, but it lags behind exactly a second no matter what interval I put it at. I don't want to put the count down timer inside the view controller as I want the timer global for all view controllers. If you have any ideas, let me know.










    share|improve this question


























      0












      0








      0








      I'm having difficulties attempting to link two timers together. I'm trying to have a timer count down from a specified amount and to have a second timer constantly updating a label on a view controller. However, I end up having the timer that updates the label lagging exactly 1 second behind the first timer in the timer class. Here's what I have for the view controller: (note that this is a condensed version of my code)



      class HomeViewController: UIViewController 
      @IBOutlet var timeLabel: UILabel!

      override func viewDidLoad()
      timeLabel.text = account.deedManager.globalTimer.timerStr

      Timer.scheduledTimer(timeInterval: 0.05, target: self, selector: #selector(UpdateTime), userInfo: nil, repeats: true)


      @objc func UpdateTime()
      self.timeLabel.text = account.deedManager.globalTimer.timerStr




      And here is the Timer class:



      class TimerModel: NSObject, NSCoding 
      var myTimer: Timer? = Timer()
      var timerInterval: TimeInterval = 1.0
      var timerEnd: TimeInterval = 0.0
      var timerCount: TimeInterval = 86400.0 // 24 hours
      var timerStr: String = "TIME"

      func StartTimer(time: Double)
      timerCount = time
      myTimer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(UpdateTime), userInfo: nil, repeats: true)


      @objc func UpdateTime()
      self.timerStr = self.TimerDate(time: self.timerCount)
      self.timerCount-=1
      print(self.timerStr)


      func TimerDate(time:TimeInterval) -> String
      let hours = Int(time) / 3600
      let minutes = Int(time) / 60 % 60
      let seconds = Int(time) % 60
      return String(format: "%02i:%02i:%02i", hours, minutes, seconds)




      I've tried to make the first timer a 0.05 interval so that it updates more rapidly than the timer class, but it lags behind exactly a second no matter what interval I put it at. I don't want to put the count down timer inside the view controller as I want the timer global for all view controllers. If you have any ideas, let me know.










      share|improve this question
















      I'm having difficulties attempting to link two timers together. I'm trying to have a timer count down from a specified amount and to have a second timer constantly updating a label on a view controller. However, I end up having the timer that updates the label lagging exactly 1 second behind the first timer in the timer class. Here's what I have for the view controller: (note that this is a condensed version of my code)



      class HomeViewController: UIViewController 
      @IBOutlet var timeLabel: UILabel!

      override func viewDidLoad()
      timeLabel.text = account.deedManager.globalTimer.timerStr

      Timer.scheduledTimer(timeInterval: 0.05, target: self, selector: #selector(UpdateTime), userInfo: nil, repeats: true)


      @objc func UpdateTime()
      self.timeLabel.text = account.deedManager.globalTimer.timerStr




      And here is the Timer class:



      class TimerModel: NSObject, NSCoding 
      var myTimer: Timer? = Timer()
      var timerInterval: TimeInterval = 1.0
      var timerEnd: TimeInterval = 0.0
      var timerCount: TimeInterval = 86400.0 // 24 hours
      var timerStr: String = "TIME"

      func StartTimer(time: Double)
      timerCount = time
      myTimer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(UpdateTime), userInfo: nil, repeats: true)


      @objc func UpdateTime()
      self.timerStr = self.TimerDate(time: self.timerCount)
      self.timerCount-=1
      print(self.timerStr)


      func TimerDate(time:TimeInterval) -> String
      let hours = Int(time) / 3600
      let minutes = Int(time) / 60 % 60
      let seconds = Int(time) % 60
      return String(format: "%02i:%02i:%02i", hours, minutes, seconds)




      I've tried to make the first timer a 0.05 interval so that it updates more rapidly than the timer class, but it lags behind exactly a second no matter what interval I put it at. I don't want to put the count down timer inside the view controller as I want the timer global for all view controllers. If you have any ideas, let me know.







      ios swift nstimer countdown






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 9 at 6:54









      rmaddy

      248k27329395




      248k27329395










      asked Mar 9 at 6:11









      KlaviamKlaviam

      11




      11






















          2 Answers
          2






          active

          oldest

          votes


















          0














          First you need to switch the order around so that you are setting the text after you decrement the timerCount:



          @objc func UpdateTime() 
          self.timerCount-=1
          self.timerStr = self.TimerDate(time: self.timerCount)
          print(self.timerStr)



          Then, you can delete the 0.05-second timer because as you said, that doesn't seem to work.



          Try using the delegate pattern instead.



          protocol TimerModelDelegate 
          func timerTextDidChange(_ timer: TimerModel, text: String)



          And then in TimerModel,



          weak var delegate: TimerModelDelegate?
          var timerStr: String = "TIME"
          didSet
          delegate?.timerTextDidChange(self, text: timerStr)




          In HomeViewController, do this:



          class HomeViewController: UIViewController, TimerModelDelegate 
          @IBOutlet var timeLabel: UILabel!

          override func viewDidLoad()
          timeLabel.text = account.deedManager.globalTimer.timerStr
          account.deedManager.globalTimer.delegate = self
          account.deedManager.globalTimer.StartTimer(time: 60)


          // You don't need the UpdateTime method here

          func timerTextDidChange(_ timer: TimerModel, text: String)
          timeLabel.text = text







          share|improve this answer

























          • The code works, but the 1 sec delay is still there.

            – Klaviam
            Mar 9 at 17:50











          • @Klaviam Can you tell me how you find out that there is a 1 second delay? Is there a difference between the time printed and the time on the label?

            – Sweeper
            Mar 9 at 17:55











          • Yes; the print() line feeds output to the console of the true time. However, the label on the viewcontroller is 1 second behind.

            – Klaviam
            Mar 9 at 18:02











          • @Klaviam I cannot reproduce this behaviour. Are you sure this is not caused by some other parts of your code that slows the UI down or something? I have also edited the answer to correct some typos. Does it work now?

            – Sweeper
            Mar 9 at 18:12


















          0














          You have this function:



          @objc func UpdateTime() 
          self.timerStr = self.TimerDate(time: self.timerCount)
          self.timerCount-=1
          print(self.timerStr)



          Replace it with



          @objc func UpdateTime() 
          self.timerCount-=1
          self.timerStr = self.TimerDate(time: self.timerCount)
          print(self.timerStr)



          Explanation:
          You first have to change the value, then display it



          Notice the first two lines are swapped. This should fix your issue.






          share|improve this answer

























          • Hmm, now it's lagging by 2 seconds instead of one. So that's not the issue.

            – Klaviam
            Mar 9 at 6:20












          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55074556%2ftimer-updating-label-1-second-behind-2nd-timer-counting-down%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          First you need to switch the order around so that you are setting the text after you decrement the timerCount:



          @objc func UpdateTime() 
          self.timerCount-=1
          self.timerStr = self.TimerDate(time: self.timerCount)
          print(self.timerStr)



          Then, you can delete the 0.05-second timer because as you said, that doesn't seem to work.



          Try using the delegate pattern instead.



          protocol TimerModelDelegate 
          func timerTextDidChange(_ timer: TimerModel, text: String)



          And then in TimerModel,



          weak var delegate: TimerModelDelegate?
          var timerStr: String = "TIME"
          didSet
          delegate?.timerTextDidChange(self, text: timerStr)




          In HomeViewController, do this:



          class HomeViewController: UIViewController, TimerModelDelegate 
          @IBOutlet var timeLabel: UILabel!

          override func viewDidLoad()
          timeLabel.text = account.deedManager.globalTimer.timerStr
          account.deedManager.globalTimer.delegate = self
          account.deedManager.globalTimer.StartTimer(time: 60)


          // You don't need the UpdateTime method here

          func timerTextDidChange(_ timer: TimerModel, text: String)
          timeLabel.text = text







          share|improve this answer

























          • The code works, but the 1 sec delay is still there.

            – Klaviam
            Mar 9 at 17:50











          • @Klaviam Can you tell me how you find out that there is a 1 second delay? Is there a difference between the time printed and the time on the label?

            – Sweeper
            Mar 9 at 17:55











          • Yes; the print() line feeds output to the console of the true time. However, the label on the viewcontroller is 1 second behind.

            – Klaviam
            Mar 9 at 18:02











          • @Klaviam I cannot reproduce this behaviour. Are you sure this is not caused by some other parts of your code that slows the UI down or something? I have also edited the answer to correct some typos. Does it work now?

            – Sweeper
            Mar 9 at 18:12















          0














          First you need to switch the order around so that you are setting the text after you decrement the timerCount:



          @objc func UpdateTime() 
          self.timerCount-=1
          self.timerStr = self.TimerDate(time: self.timerCount)
          print(self.timerStr)



          Then, you can delete the 0.05-second timer because as you said, that doesn't seem to work.



          Try using the delegate pattern instead.



          protocol TimerModelDelegate 
          func timerTextDidChange(_ timer: TimerModel, text: String)



          And then in TimerModel,



          weak var delegate: TimerModelDelegate?
          var timerStr: String = "TIME"
          didSet
          delegate?.timerTextDidChange(self, text: timerStr)




          In HomeViewController, do this:



          class HomeViewController: UIViewController, TimerModelDelegate 
          @IBOutlet var timeLabel: UILabel!

          override func viewDidLoad()
          timeLabel.text = account.deedManager.globalTimer.timerStr
          account.deedManager.globalTimer.delegate = self
          account.deedManager.globalTimer.StartTimer(time: 60)


          // You don't need the UpdateTime method here

          func timerTextDidChange(_ timer: TimerModel, text: String)
          timeLabel.text = text







          share|improve this answer

























          • The code works, but the 1 sec delay is still there.

            – Klaviam
            Mar 9 at 17:50











          • @Klaviam Can you tell me how you find out that there is a 1 second delay? Is there a difference between the time printed and the time on the label?

            – Sweeper
            Mar 9 at 17:55











          • Yes; the print() line feeds output to the console of the true time. However, the label on the viewcontroller is 1 second behind.

            – Klaviam
            Mar 9 at 18:02











          • @Klaviam I cannot reproduce this behaviour. Are you sure this is not caused by some other parts of your code that slows the UI down or something? I have also edited the answer to correct some typos. Does it work now?

            – Sweeper
            Mar 9 at 18:12













          0












          0








          0







          First you need to switch the order around so that you are setting the text after you decrement the timerCount:



          @objc func UpdateTime() 
          self.timerCount-=1
          self.timerStr = self.TimerDate(time: self.timerCount)
          print(self.timerStr)



          Then, you can delete the 0.05-second timer because as you said, that doesn't seem to work.



          Try using the delegate pattern instead.



          protocol TimerModelDelegate 
          func timerTextDidChange(_ timer: TimerModel, text: String)



          And then in TimerModel,



          weak var delegate: TimerModelDelegate?
          var timerStr: String = "TIME"
          didSet
          delegate?.timerTextDidChange(self, text: timerStr)




          In HomeViewController, do this:



          class HomeViewController: UIViewController, TimerModelDelegate 
          @IBOutlet var timeLabel: UILabel!

          override func viewDidLoad()
          timeLabel.text = account.deedManager.globalTimer.timerStr
          account.deedManager.globalTimer.delegate = self
          account.deedManager.globalTimer.StartTimer(time: 60)


          // You don't need the UpdateTime method here

          func timerTextDidChange(_ timer: TimerModel, text: String)
          timeLabel.text = text







          share|improve this answer















          First you need to switch the order around so that you are setting the text after you decrement the timerCount:



          @objc func UpdateTime() 
          self.timerCount-=1
          self.timerStr = self.TimerDate(time: self.timerCount)
          print(self.timerStr)



          Then, you can delete the 0.05-second timer because as you said, that doesn't seem to work.



          Try using the delegate pattern instead.



          protocol TimerModelDelegate 
          func timerTextDidChange(_ timer: TimerModel, text: String)



          And then in TimerModel,



          weak var delegate: TimerModelDelegate?
          var timerStr: String = "TIME"
          didSet
          delegate?.timerTextDidChange(self, text: timerStr)




          In HomeViewController, do this:



          class HomeViewController: UIViewController, TimerModelDelegate 
          @IBOutlet var timeLabel: UILabel!

          override func viewDidLoad()
          timeLabel.text = account.deedManager.globalTimer.timerStr
          account.deedManager.globalTimer.delegate = self
          account.deedManager.globalTimer.StartTimer(time: 60)


          // You don't need the UpdateTime method here

          func timerTextDidChange(_ timer: TimerModel, text: String)
          timeLabel.text = text








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 9 at 18:11

























          answered Mar 9 at 8:11









          SweeperSweeper

          73.7k1075145




          73.7k1075145












          • The code works, but the 1 sec delay is still there.

            – Klaviam
            Mar 9 at 17:50











          • @Klaviam Can you tell me how you find out that there is a 1 second delay? Is there a difference between the time printed and the time on the label?

            – Sweeper
            Mar 9 at 17:55











          • Yes; the print() line feeds output to the console of the true time. However, the label on the viewcontroller is 1 second behind.

            – Klaviam
            Mar 9 at 18:02











          • @Klaviam I cannot reproduce this behaviour. Are you sure this is not caused by some other parts of your code that slows the UI down or something? I have also edited the answer to correct some typos. Does it work now?

            – Sweeper
            Mar 9 at 18:12

















          • The code works, but the 1 sec delay is still there.

            – Klaviam
            Mar 9 at 17:50











          • @Klaviam Can you tell me how you find out that there is a 1 second delay? Is there a difference between the time printed and the time on the label?

            – Sweeper
            Mar 9 at 17:55











          • Yes; the print() line feeds output to the console of the true time. However, the label on the viewcontroller is 1 second behind.

            – Klaviam
            Mar 9 at 18:02











          • @Klaviam I cannot reproduce this behaviour. Are you sure this is not caused by some other parts of your code that slows the UI down or something? I have also edited the answer to correct some typos. Does it work now?

            – Sweeper
            Mar 9 at 18:12
















          The code works, but the 1 sec delay is still there.

          – Klaviam
          Mar 9 at 17:50





          The code works, but the 1 sec delay is still there.

          – Klaviam
          Mar 9 at 17:50













          @Klaviam Can you tell me how you find out that there is a 1 second delay? Is there a difference between the time printed and the time on the label?

          – Sweeper
          Mar 9 at 17:55





          @Klaviam Can you tell me how you find out that there is a 1 second delay? Is there a difference between the time printed and the time on the label?

          – Sweeper
          Mar 9 at 17:55













          Yes; the print() line feeds output to the console of the true time. However, the label on the viewcontroller is 1 second behind.

          – Klaviam
          Mar 9 at 18:02





          Yes; the print() line feeds output to the console of the true time. However, the label on the viewcontroller is 1 second behind.

          – Klaviam
          Mar 9 at 18:02













          @Klaviam I cannot reproduce this behaviour. Are you sure this is not caused by some other parts of your code that slows the UI down or something? I have also edited the answer to correct some typos. Does it work now?

          – Sweeper
          Mar 9 at 18:12





          @Klaviam I cannot reproduce this behaviour. Are you sure this is not caused by some other parts of your code that slows the UI down or something? I have also edited the answer to correct some typos. Does it work now?

          – Sweeper
          Mar 9 at 18:12













          0














          You have this function:



          @objc func UpdateTime() 
          self.timerStr = self.TimerDate(time: self.timerCount)
          self.timerCount-=1
          print(self.timerStr)



          Replace it with



          @objc func UpdateTime() 
          self.timerCount-=1
          self.timerStr = self.TimerDate(time: self.timerCount)
          print(self.timerStr)



          Explanation:
          You first have to change the value, then display it



          Notice the first two lines are swapped. This should fix your issue.






          share|improve this answer

























          • Hmm, now it's lagging by 2 seconds instead of one. So that's not the issue.

            – Klaviam
            Mar 9 at 6:20
















          0














          You have this function:



          @objc func UpdateTime() 
          self.timerStr = self.TimerDate(time: self.timerCount)
          self.timerCount-=1
          print(self.timerStr)



          Replace it with



          @objc func UpdateTime() 
          self.timerCount-=1
          self.timerStr = self.TimerDate(time: self.timerCount)
          print(self.timerStr)



          Explanation:
          You first have to change the value, then display it



          Notice the first two lines are swapped. This should fix your issue.






          share|improve this answer

























          • Hmm, now it's lagging by 2 seconds instead of one. So that's not the issue.

            – Klaviam
            Mar 9 at 6:20














          0












          0








          0







          You have this function:



          @objc func UpdateTime() 
          self.timerStr = self.TimerDate(time: self.timerCount)
          self.timerCount-=1
          print(self.timerStr)



          Replace it with



          @objc func UpdateTime() 
          self.timerCount-=1
          self.timerStr = self.TimerDate(time: self.timerCount)
          print(self.timerStr)



          Explanation:
          You first have to change the value, then display it



          Notice the first two lines are swapped. This should fix your issue.






          share|improve this answer















          You have this function:



          @objc func UpdateTime() 
          self.timerStr = self.TimerDate(time: self.timerCount)
          self.timerCount-=1
          print(self.timerStr)



          Replace it with



          @objc func UpdateTime() 
          self.timerCount-=1
          self.timerStr = self.TimerDate(time: self.timerCount)
          print(self.timerStr)



          Explanation:
          You first have to change the value, then display it



          Notice the first two lines are swapped. This should fix your issue.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 9 at 18:13









          Koen

          2,27022459




          2,27022459










          answered Mar 9 at 6:14









          DaniFoldiDaniFoldi

          13911




          13911












          • Hmm, now it's lagging by 2 seconds instead of one. So that's not the issue.

            – Klaviam
            Mar 9 at 6:20


















          • Hmm, now it's lagging by 2 seconds instead of one. So that's not the issue.

            – Klaviam
            Mar 9 at 6:20

















          Hmm, now it's lagging by 2 seconds instead of one. So that's not the issue.

          – Klaviam
          Mar 9 at 6:20






          Hmm, now it's lagging by 2 seconds instead of one. So that's not the issue.

          – Klaviam
          Mar 9 at 6:20


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55074556%2ftimer-updating-label-1-second-behind-2nd-timer-counting-down%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          1928 у кіно

          Захаров Федір Захарович

          Ель Греко