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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:15:32+00:00 2026-06-11T18:15:32+00:00

I am trying to do the following: 1) user clicks button start , it

  • 0

I am trying to do the following:

1) user clicks button start, it runs startTimer method, which sets a new [NSDate date].

2) user clicks button stop it runs stopTimer method, which retrieves the [NSDate date] value.

I can’t get step number 2 working. I’ve set it in the .h file. If I copy the code from the start method into the stop method it works. So, I can set the [NSDate date]. But, this is not what I want. I want to be able to set it in the startTimer method. How do i go about this?

.h file

@interface StartTest : UIViewController {
    IBOutlet UILabel *timer;

    NSDate *startNSDate;
    NSDate *start;



}

- (IBAction)startTimer;
- (IBAction)stopTimer;

- (NSDate *)setStart;
- (NSDate *)getStart;


@end

.m file:

@implementation Ash

- (IBAction)startTimer {

    startNSDate = [NSDate date];

}


- (IBAction)stopTimer{

    start = [NSDate date];


    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy"];


    NSString *stringFromDate = [formatter stringFromDate:startNSDate]; // <<< this is where it fails

    NSLog(@"stringfromdate: %@", stringFromDate);
}
  • 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-11T18:15:33+00:00Added an answer on June 11, 2026 at 6:15 pm

    startNSDate isn’t retained and by the time you want to access it, it’s already dealloc’d, hence you’re trying to access garbage pointer

    easiest solution for you will be

    @interface StartTest : UIViewController {
        IBOutlet UILabel *timer;
    
        NSDate *startNSDate;
        NSDate *start;
    
    
    
    }
    @property (nonatomic, strong) NSDate* startNSDate;
    
    - (IBAction)startTimer;
    - (IBAction)stopTimer;
    
    - (NSDate *)setStart;
    - (NSDate *)getStart;
    
    
    @end
    
    
    
    
    @implementation Ash
    
    - (IBAction)startTimer {
    
        self.startNSDate = [NSDate date];
    
    }
    
    
    - (IBAction)stopTimer{
    
        start = [NSDate date];
    
    
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"yyyy"];
    
        // this is where it fails, the reason being that startNSDate isn't retained
        // and by this line, it's already dealloc'd, hence you're trying to access
        // garbage pointer
        NSString *stringFromDate = [formatter self.startNSDate]; 
    
        NSLog(@"stringfromdate: %@", stringFromDate);
    }
    
    - (void)dealloc
    {
        self.startNSDate = nil;
        [super dealloc];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I am trying to achieve the following: 1) User clicks on file input
I am trying the following code to AutoComplete contact details as the user types
I'm trying to run the following PowerShell script to create a local user. This
I hope someone can help with the following. I'm trying to create a user-specific
I am trying following, 1. Get response using Ajax from the users selection which
I am trying to use the following javascript code to alert the user when
I am trying to build an application which does the following : 1) write
When a user clicks a button, I use the ThreadPool.QueueUserWorkItem to spawn a thread
I'm trying to do something with Chrome's new speech recognition abilities with HTML5. Following
I have a form, when the user clicks on the submit button this javascript

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.