PDA

View Full Version : How do I create a "stopwatch" in my iPhone app?




ethana
Jul 17, 2008, 02:20 AM
I'm trying to create an app that has a Stopwatch type feature in it, but I want to type as little code as possible to do it. Basically, I want to have exactly what the Clock>Stopwatch iPhone app has and put it right into one of my apps.

Anyone have any clue if this can be done easily? Or do I have to do this the hard way with timers, loops, etc. Please post reusable code if you can. Thanks!

Ethan



detz
Jul 17, 2008, 06:22 AM
No loop, you app will lock up. Use a timer, easy enough...

[NSTimer scheduledTimerWithTimeInterval:(1)
target:self
selector:@selector(goDude)
userInfo:nil
repeats:YES];

-(void)goDude{
//every second this is called.
}

alexalol
Aug 2, 2008, 01:13 AM
hi
i am new to iphone programming and just want to know just how accurate can this "stopwatch" app be made; can it only count seconds or can it be made to count tens (0.1s) and hundreds (0.01s) of a second?

detz
Aug 2, 2008, 06:24 AM
hi
i am new to iphone programming and just want to know just how accurate can this "stopwatch" app be made; can it only count seconds or can it be made to count tens (0.1s) and hundreds (0.01s) of a second?

NSTimeInterval is always specified in seconds; it yields sub-millisecond precision over a range of 10,000 years.

alexalol
Aug 2, 2008, 02:11 PM
NSTimeInterval is always specified in seconds; it yields sub-millisecond precision over a range of 10,000 years.
ok tnx :)

is there any other function which is specified in miliseconds?

detz
Aug 2, 2008, 03:08 PM
ok tnx :)

is there any other function which is specified in miliseconds?

That function works with milliseconds, give it a try. :)