• 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
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NSDate scope
      • From: Kyle Sluder <email@hidden>
    • Re: NSDate scope
      • From: Ken Thomases <email@hidden>
  • Prev by Date: Re: How to fill rectangle under vertical scroller?
  • Next by Date: Re: Just implementing -isEqual:, never invoked, causes crash
  • Previous by thread: [WORKAROUND] Re: new NSTreeController bug in 10.5.7?
  • Next by thread: Re: NSDate scope
  • Index(es):
    • Date
    • Thread