IPhone : objective-C date conversion generate nil

on Sunday, March 29, 2015

the following objective-C code 6.2 ( SDK 8.2) :



NSArray *the_datums = [[readCSV alloc] read_csv_from_url:fname] ;// is an array of date in Y-M-D H format read from a CSV file
NSMutableArray *les_dates = [[NSMutableArray alloc] init];

for (int i =0 ; i< the_datums.count ; i++){

NSString *str = [the_datums objectAtIndex:i] ;

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd H"];

NSDate *date = [dateFormatter dateFromString: str];

dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"d"];

NSString *convertedString = [dateFormatter stringFromDate:date];
[les_dates insertObject:convertedString atIndex:i];


}


works if the Iphone/Ipad is not in AM:PM mode(via IOS control panel). BUT if i switch the idevice to AM:PM and relaunch the APP , Xcode throws me stones on my face :


* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSArrayM insertObject:atIndex:]: object cannot be nil'


How can NSdateFormatter result change and be nil when user changes the format of the iphone clock ?


0 comments:

Post a Comment