Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8487035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:07:11+00:00 2026-06-10T21:07:11+00:00

I have an NSTimer that acts for the basis of a stopwatch. – (void)startTimer

  • 0

I have an NSTimer that acts for the basis of a stopwatch.

- (void)startTimer
{
    _startDate = [NSDate date];
    _timer = [NSTimer scheduledTimerWithTimeInterval:1.0/10.0
                                              target:self 
                                            selector:@selector(updateTimer) 
                                            userInfo:nil 
                                             repeats:YES];
}

I need to record lap times, but I am running into the issue that 2 separate lap times should not share any overlap.

i.e if lap 1 starts at 0.0 and ends at 10.0, then lap 2 should start at 10.01
But at the moment when there is lap I just take the current time, to work out both the end of the previous lap and the start of the new one:

- (void)lap
{
    NSTimeInterval timeInterval = [[NSDate date] timeIntervalSinceDate:_startDate];
    timeInterval += _timeElapsed;

    _startDate = [NSDate date];
}

I need to save the start/end times of each lap as well as their total length. But I cannot see how to do this without having the start/end times be the same for different laps.

Has anyone run into this issue? Any ideas how I can solve it sensibly. Everything I think of feels very brittle.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:07:12+00:00Added an answer on June 10, 2026 at 9:07 pm

    If it is a true lap timer, as I understand, then your assumption that two separate laps should have a gap in them ins not accurate. Specifically, the statement:

    i.e if lap 1 starts at 0.0 and ends at 10.0, then lap 2 should start
    at 10.01

    is incorrect for my understanding of a lap timer. The second lap starts immediately, as the start of lap2 is the same as the stop of lap1. Otherwise, you are losing time with those gaps.

    I suggest saving only each individual time. So, if you went 5 laps, there should be size times (five if you always start at zero). You now have a time marking for the begin, and end of each lap.

    0.00
    10.03
    20.04
    30.09
    40.20
    50.33
    

    The total time is 50.53, and the time for the third lap is 10.05 (30.09 – 20.04). The sum of all individual laps should equal the total time.

    Now, you easily have the total time and the time for each lap. Pretend these values were stored in an array, you could easily do:

    - (void)startStopLap {
        // compute elapsed time...
        [self.times addObject:[NSNumber numberWithDouble:elapsedTime]];
    }
    
    - (double)totalTime {
        [[self.times lastObject] doubleValue]
            - [[self.times objectAtIndex:0] doubleValue];
    }
    
    - (double)timeForLap:(NSUInteger)lap {
        // Example assumes first lap is lap '1' and that you do
        // appropriate error checking...
        return [[self.times objectAtIndex:lap] doubleValue]
             - [[self.times objectAtIndex:lap-1] doubleValue];
    }
    

    Similarly, you can get the time for the first N laps, with simple subtraction, and you could get the times for specific ranges of laps (i.e., laps 2-4).

    Hopefully, that makes sense, and I don’t have too many typos without a compiler to check…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written the following code: -(void)runTimer { myTicker=[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(showActivity) userInfo:nil repeats:YES];
I have this code: NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:temp/10.0f target:self selector:@selector(verify) userInfo:nil repeats:YES]; CCMoveTo
Have a question... I have Timer [NSTimer scheduledTimerWithTimeInterval:120 target:self selector:@selector(action1:) userInfo:nil repeats:YES]; But when
I have an NSTimer that I initialize with scheduledTimerWithTimeInterval: with a very short interval
I have a timer that launches in viewDidLoad that looks like this [NSTimer scheduledTimerWithTimeInterval:0.001f
Here I have a code that sets fireDate of an NSTimer object. -(void)TimerFired:(NSTimer*)timer{ long
I have a NSDate variable. From that variable, how I can show a stopwatch
I have an NSTimer running in my application that collects some data and sends
I have created an app that uses NSTimer, which gets triggered each second. My
I need to start NSTimer by 0:0:0 that I am doing and I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.