Re: NSCalendarDate from plist
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