NSTimer for Chronometer

Discussion in 'iOS Programming' started by powwowath, Dec 21, 2008.

  1. macrumors newbie

    Nov 2, 2008
    Hi again mates,

    it may be a newbie question, but,.. I'm trying add a chronometer to my app and I'm looking NSTimer to create it. Is it a good idea?

  2. macrumors regular


    Jul 18, 2008
    Yes and no - yes, you'll want an NSTimer that updates every second (or more often) to update your display of the elapsed time.

    However, it may not get called exactly on time every time - so if you just use the timer to add +1 to the number of seconds elapsed, it will probably get out of sync and become innacurate. So you will also want to look at NSDate to figure out elapsed time.

    You'll probably want something like this:

    (1) create a date objects
    (2) set up an nstimer to fire every second
    (3) in the method called by the nstimer, check how much time has elapsed from the date until now.
    (4) update the display with the amount of time elapsed.
  3. thread starter macrumors newbie

    Nov 2, 2008

Share This Page