• 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
Re: NSCalendarDate from plist
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSCalendarDate from plist


  • Subject: Re: NSCalendarDate from plist
  • From: Kurt Revis <email@hidden>
  • Date: Sun, 25 Nov 2001 10:50:39 -0800

I am reading a date from a plist I created in PropertyListEditor which I need to be an NSCalendarDate rather than the CFDate/NSDate it forms by default, but I couldn't find anything to do this short of ditching dates all together and using a string(in the plist) and passing it to dateWithNaturalLanguageString: to make an NSCalendarDate. There must be an easier/faster/cleaner way than that.

You can change an NSDate into an NSCalendarDate pretty easily. Just do something like this:

NSDate *date;
NSCalendarDate *calDate;

// ... get date here...
calDate = (NSCalendarDate *)[NSCalendarDate dateWithTimeIntervalSinceReferenceDate:[date timeIntervalSinceReferenceDate]];

Note that NSCalendarDate is a subclass of NSDate, so you can still call any NSDate class methods on NSCalendarDate. People tend to overlook this...

(The cast above is because +[NSDate dateWithTimeIntervalSinceReferenceDate] is declared to return an NSDate. In actuality, though, we know that NSCalendarDate's implementation of that method will always return an NSCalendarDate. Unfortunately there's no way to express this in Objective-C (it's called covariant return types, I think), so you have to resort to casting to stop the compiler from emitting a warning.)

Does this help?

--
Kurt Revis
email@hidden


  • Follow-Ups:
    • Re: NSCalendarDate from plist
      • From: "Erik M. Buck" <email@hidden>
  • Prev by Date: NSCalendarDate from plist
  • Next by Date: Re: Announcement (and question): OCSmart Hacks
  • Previous by thread: NSCalendarDate from plist
  • Next by thread: Re: NSCalendarDate from plist
  • Index(es):
    • Date
    • Thread