• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSDate scope question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSDate scope question


  • Subject: NSDate scope question
  • From: Dan Lemmon <email@hidden>
  • Date: Sun, 5 Nov 2006 02:33:16 +1300

Hi,

I want to set a set a startDate when an object instance initializes and then periodically check it against the current date. I'm having difficulty getting it to work.

	NSDate *startDate;
	NSTimeInterval elapsedTime;
	NSTimer *timer;

	- init
	{
	    [super init];

		startDate = [NSDate date];
   	    elapsedTime = 0;
		timer = [NSTimer scheduledTimerWithTimeInterval:1.0
					target:self selector:@selector(fireTimer:)
					userInfo:nil repeats:YES];

		return self;
	}

	- (void)fireTimer:(NSTimer *)timer
	{
		printf( "Count: %f\n", elapsedTime );
	    elapsedTime = [startDate timeIntervalSinceNow];
	}

This will compile, but fails at runtime and gives the error GDB: Program received signal: "EXC_BAD_ACCESS". when I step through in the debugger. It doesn't like any reference to startDate in the fireTimer: method, unless startDate is set within that method.

I'm new to Cocoa and OOP in general, so I'm sure I'm probably just doing something stupid. Any suggestions would be greatly appreciated.

Thanks,
-Dan

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSDate scope question
      • From: Cameron Hayne <email@hidden>
  • Prev by Date: Re: How do you append the data to the URL while POSTING?
  • Next by Date: Re: NSDate scope question
  • Previous by thread: Re: Spell Checking Text Views
  • Next by thread: Re: NSDate scope question
  • Index(es):
    • Date
    • Thread