How do I create a "stopwatch" in my iPhone app?

Discussion in 'iOS Programming' started by ethana, Jul 17, 2008.

  1. macrumors 6502a

    Joined:
    Jul 17, 2008
    Location:
    Seattle, WA
    #1
    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
     
  2. macrumors 65816

    Joined:
    Jun 29, 2007
    #2
    No loop, you app will lock up. Use a timer, easy enough...

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

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

    Joined:
    Aug 1, 2008
    #3
    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?
     
  4. macrumors 65816

    Joined:
    Jun 29, 2007
    #4
    NSTimeInterval is always specified in seconds; it yields sub-millisecond precision over a range of 10,000 years.
     
  5. macrumors newbie

    Joined:
    Aug 1, 2008
    #5
    ok tnx :)

    is there any other function which is specified in miliseconds?
     
  6. macrumors 65816

    Joined:
    Jun 29, 2007
    #6
    That function works with milliseconds, give it a try. :)
     

Share This Page