NSShortDateFormatString etc. deprecated in Leopard - what should I use instead?
NSShortDateFormatString etc. deprecated in Leopard - what should I use instead?
- Subject: NSShortDateFormatString etc. deprecated in Leopard - what should I use instead?
- From: Manfred Schwind <email@hidden>
- Date: Fri, 7 Dec 2007 15:15:34 +0100
Hi,
I have the following line of code:
NSString *shortDateFormatString = [[NSUserDefaults
standardUserDefaults] objectForKey:NSShortDateFormatString];
When compiling with 10.5 SDK, I got the following warning:
warning: 'NSShortDateFormatString' is deprecated (declared at /
Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/
Foundation.framework/Headers/NSUserDefaults.h:98)
In the header file, I can find:
/* The following keys and their values are deprecated in Mac OS X 10.5
"Leopard". Developers should use NSLocale, NSDateFormatter and
NSNumberFormatter to retrieve the values formerly returned by these
keys.
*/
My problem is: I can not figure out how I can replace the above line
of code with code of NSLocale, NSDateFormatter or NSNumberFormatter!
All I want to do is: get the format string for the short date format
that you e.g. can see in System Preferences - International - Formats
(the last line in the Dates examples). How can I get this value?
I tried the following code:
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init]
autorelease];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_0]; //
to get e.g. "%d" instead of "dd"
[dateFormatter setLocale:[NSLocale currentLocale]];
[dateFormatter setDateStyle:kCFDateFormatterShortStyle]; // short date
[dateFormatter setTimeStyle:kCFDateFormatterNoStyle]; // no time
NSString *shortDateFormatString = [dateFormatter dateFormat];
But I do not get the correct result. I always get back an english date
format string "%m/%d/%y".
But my system is configured in german and therefore the correct format
string is "%d.%m.%y" and I get that back correctly with the deprecated
NSShortDateFormatString key. But what's the Leopard way to get that
format string?
Regards,
Mani
--
http://www.mani.de
iVolume - Loudness adjustment for iTunes.
LittleSecrets - The encrypted notepad.
_______________________________________________
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