I am trying to combine a string date and time then convert that to an NSDate. My code is:
NSMutableArray *arrayOfDatesAsDates = [[NSMutableArray alloc] init];
NSDateFormatter *dateAndTimeFormatter = [[NSDateFormatter alloc] init];
[dateAndTimeFormatter setLocale:enUSPOSIXLocale];
[dateAndTimeFormatter setDateFormat:@"dd-MM-yyyy HH:mm"];
NSLog(@"here");
//create an NSDate with todays date and the right prayer time
NSString *prayerDateString = [curDate stringByAppendingString: @" "];
prayerDateString = [prayerDateString stringByAppendingString: timeOfMagrib];
NSDate *prayerDateAndTime = [dateAndTimeFormatter dateFromString:prayerDateString]; //convert string back to date
NSLog(@"nsdate %@", prayerDateAndTime);
[arrayOfDatesAsDates addObject:prayerDateAndTime];
The output to the log of prayerDateAndTime is 2013-07-08 20:26:00 +0000 as expected and the error message is Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
.
It crashes at the [arrayOfDatesAsDates addObject:prayerDateAndTime];
line.
Why is this?
Many thanks