1

There are lots of questions about using NSTimer for timer functions but I am instead using a CocoaPod "Countdown Label" https://github.com/suzuki-0000/CountdownLabel

My question/problem specifically is how to trigger an action/notification once it is complete I don't believe this to be the same as the many "NSTimer" questions/tutorials but please correct me if I'm wrong!

I've read the Timer documentation here https://developer.apple.com/documentation/foundation/timer but, again, don't see how it would apply to a 'custom timer library' like this Cocoapod.

I am currently trying this....

func testTimer() {

    timerLabel.countdownDelegate = self
    timerLabel.start()
        if self.timerLabel.isFinished {
        print("timer it's finished")
        } else {self.timerLabel.start()
    }
}

testTimer() is then called when an IBAction is pressed to star the timer.

My logic/thinking was that this function starts the timer, then checks if it finished. If it isn't finished it starts/continues the timer (timerLabel.start) and checks again basically in a loop until it is finished and then prints "timer is finished" but this isn't working and I'm not sure why? (but builds fine)

I know I could just scrap the pod and follow a Timer() tutorial but I'm trying to learn/understand how this sort of 'internal notification' for non Apple libraries would work generally at the same time as solving this specific problem. I hope this all makes sense.

NB. Some of the questions/answers I've read through that I don't believe are what I need are How to check if a NSTimer is running or not in Swift?, Check if Timer is running, Perform segue when timer is finished but they all use the Apple "Timer()".

NB. I am setting up the timer is ViewDidLoad with data from a Segue like this :

 let timerLabelTime = Int(selectedWorkoutTime)
            timerLabel.setCountDownTime(minutes: Double((timerLabelTime)!*60))
                    timerLabel.countdownDelegate = self
                    timerLabel.pause()

which works fine

rmaddy
  • 314,917
  • 42
  • 532
  • 579
nc14
  • 539
  • 1
  • 8
  • 26
  • It seems that you can use the `then()` method to provide a closure or be executed at a particular time remaining value or set a delegate and receive delegate method call backs each second – Paulw11 Apr 28 '18 at 21:20
  • sorry would you be able to elaborate? I did see the "then method" but I'm not sure how it would be used (and where) to simply 'do something when timer is finished' - I have added the CountdowbLabelDelegate to my VC – nc14 Apr 28 '18 at 21:22
  • You can use it anywhere you want; `viewDidAppear`, for example. `myCountdown.then(0) { code to execute at 0}`. I haven't ever used this control but that is what the documentation seems to show – Paulw11 Apr 28 '18 at 21:24

0 Answers0