Search code examples
iosobjective-cnstimer

Calling A Function Before NSTimer Fires


I have an NSTimer which fires after 1 minutes but I want to display a warning when the remaining time till fire is 10 seconds. How do I present an alert when the remaining time is 10 seconds?


Solution

    • Declare a counter with value 0.
    • Set the timer to fire repeating after 10 seconds.
    • When the timer fires increment the counter.
      • If the counter is 5 show the alert.
      • If the counter is 6 destroy the timer and do what you are going to do when the timer fires.