开发者

dateFromString with iOs 4.3

I have a tr开发者_如何学Couble with the iOs 4.3 GM seed. When I launch this code :

// Set the dates
NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc]init] autorelease];
[dateFormatter setDateFormat:@"y G"]; 
NSDate* date = [dateFormatter dateFromString:@"3000 av. J.-C."];

It's giving me this error : * Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSCFString substringFromIndex:]: Range or index out of bounds' error.

This wasn't the case with iOS 4.2. Do you know where it is coming from ? (I can use @"3000 BC"format, it is working, but I'd like to understand where does this crash comes from)


Answer : I have to choose the locale system of the date formatter and keep only one date format.

NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"fr_FR"] autorelease];
[dateFormatter setLocale:locale];

Before the system was accepting "3000 av. J.-C." and "3000 BC" notation without setting the locale system, now it's not. I guess Apple want us to specify the date format to avoid guessing it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜