Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

powwowath

macrumors newbie
Original poster
Nov 2, 2008
8
0
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?

thnks!
 

xsmasher

macrumors regular
Jul 18, 2008
140
0
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?

thnks!

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.