NSDate scope question
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