NSDate scope
NSDate scope
- Subject: NSDate scope
- From: John Baldwin <email@hidden>
- Date: Sat, 20 Jun 2009 16:52:41 -0700
This is mostly a curiosity. I've found a working solution by using
time intervals, but still don't fully understand why my program would
crash when I used dates.
I declared a (NSDate *) in my .h file.
NSDate *originalDate;
Then in my init method, I initialized it to the current date. I tried
various methods, all with the same result:
originalDate = [NSDate date];
originalDate = [NSDate dateWithTimeIntervalSinceNow:0];
originalDate = [[NSDate alloc] init];
originalDate = [[NSDate date] retain];
(I probably tried others, too.)
Then, in a method that was called by an NSTimer object, I tried to use
that date as a reference point. But the debugger showed the variable
as "out of scope."
NSDate *currentDate = [NSDate date];
NSTimeInterval secs = [currentDate timeIntervalSinceDate originalDate];
The variable would be out of scope, and the program would crash upon
referencing it. I searched google and other sources, but the only hint
(I found) was that it might have something to do with it being a class
cluster.
So what makes using NSDate in this way invalid?
John
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden