FROM : Jonathan Fewtrell
DATE : Sat Apr 16 19:59:33 2005
On 16 Apr 2005, at 17:17, glenn andreas wrote:
> you could write your own NSDateFormatter subclass instead (and then
> use that). Something roughly like:
>
> @interface ShortDateFormatter: NSDateFormatter
> @end
>
> @implementation ShortDateFormatter
> - (NSString *) dateFormat
> {
> return [[NSUserDefaults standardUserDefaults] stringForKey:
> NSShortDateFormatString];
> }
> @end
As a follow-up to this, I found that overriding -dateFormat doesn't
work. It still picks up the format from the tokens in IB. I found I
needed to override -initWithDateFormat instead:
- (id)initWithDateFormat:(NSString *)format
allowNaturalLanguage:(BOOL)flag
{
NSString *formatJF;
formatJF = [[NSUserDefaults standardUserDefaults] stringForKey:
NSShortDateFormatString];
self = [super initWithDateFormat:formatJF allowNaturalLanguage:flag];
return self;
}
Not really sure why this should be, but the docs do actually say "You
must specify a format string whenever you create a date formatter".
DATE : Sat Apr 16 19:59:33 2005
On 16 Apr 2005, at 17:17, glenn andreas wrote:
> you could write your own NSDateFormatter subclass instead (and then
> use that). Something roughly like:
>
> @interface ShortDateFormatter: NSDateFormatter
> @end
>
> @implementation ShortDateFormatter
> - (NSString *) dateFormat
> {
> return [[NSUserDefaults standardUserDefaults] stringForKey:
> NSShortDateFormatString];
> }
> @end
As a follow-up to this, I found that overriding -dateFormat doesn't
work. It still picks up the format from the tokens in IB. I found I
needed to override -initWithDateFormat instead:
- (id)initWithDateFormat:(NSString *)format
allowNaturalLanguage:(BOOL)flag
{
NSString *formatJF;
formatJF = [[NSUserDefaults standardUserDefaults] stringForKey:
NSShortDateFormatString];
self = [super initWithDateFormat:formatJF allowNaturalLanguage:flag];
return self;
}
Not really sure why this should be, but the docs do actually say "You
must specify a format string whenever you create a date formatter".
| Related mails | Author | Date |
|---|---|---|
| Jonathan Fewtrell | Apr 16, 18:06 | |
| glenn andreas | Apr 16, 18:17 | |
| Jonathan Fewtrell | Apr 16, 18:44 | |
| glenn andreas | Apr 16, 18:49 | |
| Jonathan Fewtrell | Apr 16, 18:55 | |
| Jonathan Fewtrell | Apr 16, 19:59 |






Cocoa mail archive

