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 7168271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:44:48+00:00 2026-05-28T14:44:48+00:00

I want to display, on screen, the elapsed time since some event. I have

  • 0

I want to display, on screen, the elapsed time since some event. I have a member variable

NSDate *_startTime;

I allocate it (and initiate a timer) like so:

_startTime = [NSDate date];
_timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(clock) userInfo:nil repeats:YES];

My clock function gets called fine but when I attempt to find the elapsed time I get a crash with no real way of determining what happens; I simple get EXC_BAD_ACCESS. Below is how I attempt to get the elapsed time since _startDate which throws the exception:

NSTimeInterval secondsElapsed = [_startTime timeIntervalSinceNow];

It crashes on this line – I have looked around and this seems to be the correct syntaax, what is happening here?

  • 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-05-28T14:44:49+00:00Added an answer on May 28, 2026 at 2:44 pm

    Unless you’re using ARC, you need to have ownership of the NSDate object that you’re storing in _startTime. +[NSDate date] returns an object you don’t own, and it is likely to have been deallocated and therefore to be invalid by the time you get around to sending it timeIntervalSinceNow.

    You can create an owned NSDate like so:

    // By default, NSDates are initialized with the current date
    _startTime = [[NSDate alloc] init];
    

    or by explicitly taking ownership of the return value of +date:

    _startTime = [[NSDate date] retain];
    

    They are equivalent in effect.

    Even better (assuming you have a property defined for _startTime (which you should)) would be using the setter:

    [self setStartTime:[NSDate date]];
    

    With the property defined as retaining, this will handle the memory correctly.

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

Sidebar

Related Questions

I have a <div> which I want to display full screen, but I also
I want to display two Activities on one screen at time, and I suppouse
I want to display an error message on an Android app screen after some
i want to display both TextBox and TextField on the screen at a time
I have a picture (jpg) that I want to display on the screen. Additionally
I want to display three buttons in the middle of a screen, and have
I have a large image on the screen and I want to display a
HI, I want to display 20 random images at a time over Activity screen
I have 9 pictures that I want to display on screen so they take
I want to know that is it possible to display full screen ad directly

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.