Re: Question about laterDate: and earlierDate:
Re: Question about laterDate: and earlierDate:
- Subject: Re: Question about laterDate: and earlierDate:
- From: Mike Abdullah <email@hidden>
- Date: Tue, 16 Oct 2007 16:10:16 +0100
On 16 Oct 2007, at 14:59, Paul Bruneau wrote:
On Oct 16, 2007, at 9:35 AM, Mike Abdullah wrote:
Indeed the compiler has spotted that -laterDate returns an NSDate
rather than NSCalendarDate. Can you be sure that an actual
NSCalendarDate object is being returned? If so, you could something
like this:
[selectedOS setStartTime:(NSCalendarDate *)[testedStartTime
laterDate:now]];
Thank you Mike for your reply. I see that you are "casting" the
response from -laterDate: to be an NSCalendarDate (if I am using the
incorrect term, please excuse me because I come from a different Mac
dev environment than most)
That is the correct term indeed
I can be sure of the type that is returned but I agree this isn't
the best thing. I still wonder why is -laterDate: returning an
NSDate. Isn't it true that since NSCalendarDate is a subclass of
NSDate it should have full use of the superclass' methods without
this kind of hassle? We don't get the same problem when we use
methods from NSArray in our NSMutableArrays do we?
You get basically the same behaviour with NSArray. e.g.
- (NSArray *)objectsAtIndexes:(NSIndexSet *)indexes
It's just not normally an issue since you don't generally care about
getting back a mutable array specifically.
However, I should point out that that isn't particularly good
practice really. If you can afford to only target 10.4 and later,
you should really use NSDate and NSCalendar rather than
NSCalendarDate.
I can afford to target 10.4 since this app is for a single user
under my control, but I like the methods that exist in
NSCalendarDate. I heard in Big Nerd Ranch's Cocoa Boot Camp last
July that people were turning away from NSCalendarDate due to
localization concerns IIRC. Is there some documentation from Apple
that can fully explain to me why I shouldn't use NSCalendarDate? I
have no such localization concerns in my case but am still interested.
Well the localization issue is simply that NSCalendarDate only
supports the Gregorian calendar. NSCalendar works by splitting that
localization-specific code out into a separate class so you can
support multiple calendars. One other good reason is that Core Data
will only store NSDates, not NSCalendarDates.
Thanks again
_______________________________________________
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
_______________________________________________
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