Re: NSDateFormatter initialization+formatting not working
Re: NSDateFormatter initialization+formatting not working
- Subject: Re: NSDateFormatter initialization+formatting not working
- From: Ken Thomases <email@hidden>
- Date: Sat, 19 Feb 2011 22:18:55 -0600
On Feb 19, 2011, at 9:53 PM, Markus Spoettl wrote:
> NSDateFormatter *df1 = [[NSDateFormatter alloc] initWithDateFormat:@"EEE d" allowNaturalLanguage:NO];
> NSString *s1 = [df1 stringFromDate:date];
>
> s1 ---> @"EEE d";
>
> NSDateFormatter *df2 = [[NSDateFormatter alloc] init];
> [df2 setDateFormat:@"EEE d"];
> NSString *s2 = [df2 stringFromDate:date];
>
> s2 ---> @"Sat 19" (on a Saturday the 19th)
> And why doesn't the -initWithDateFormat: initializer work?
I think it does work, but produces a formatter using the old-style behavior. From <http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/>:
> If you initialize a formatter using initWithDateFormat:allowNaturalLanguage:, you are (for backwards compatibility reasons) creating an “old-style” date formatter. To use the new behavior, you initialize the formatter with init. If necessary, you can set the default class behavior using setDefaultFormatterBehavior:), you can set the behavior for an instance using setFormatterBehavior: message with the argument NSDateFormatterBehavior10_4.
My best guess about -init is not so much that it is deprecated to invoke that method, but that there used to be an override with its own documentation, but now it's just implicit that -init is inherited from NSObject. So, the old method documentation was removed from the class reference and put in a "deprecated" page. If you look at the header, there is a commented-out declaration of -init with a comment saying it is the designated initializer. In previous versions of that header, the -init method declaration was not commented out.
Regards,
Ken
_______________________________________________
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