Let me start off by saying Im VERY new to iphone development, but Im trying really hard to learn, so any help any of you professionals out there are willing to share is greatly appreciated! So I have a question that would be SO awesome if someone could answer for me. I am studying up more one core data and have been using the core data books example from the apple developer website found here. It is a pretty straight forward application, but I am trying to change something and I can't figure out how to do it and it is driving me CRAZY!!! Natively, the app shows the author in the tableview section heading, with the title in the cell. I would like to change that and set the copyright date (one of the attributes of the book) as the section header. Right now, I can get it to show, but it shows the date in this format:
2009-12-01 10:11:31 -0700
But thats not the right format, Id like to use this format:
Tuesday December 1
Probably using this code:
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"EEEE MMMM d"];
NSString *date = [outputFormatter stringFromDate:[NSDate date]];
but the problem is that the date value is coming in from the datepicker, and I can't figure out (with all this crazy 'key' business) how to format the date value that came from the picker and put it onto the section header. If you have any time to possibly follow the link to the apple wbsite above and poke around until you can answer my dilema, IT WOULD BE SO APPRECIATED!!!! Thank you.
Okay so here is my code I put in the save method:
// Pass current value to the edited object, then pop.
if (editingDate) {
NSString *rawDate = (NSString *)datePicker.date;
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"yyyy-MM-dd"];
NSDate *date = (NSDate *)[outputFormatter dateFromString:rawDate];
[outputFormatter setDateFormat:@"EEEE MMMM d"];
NSString *formattedDateStr = (NSString *)[outputFormatter stringFromDate:date];
[editedObject setValue:(NSDate *)formattedDateStr forKey:editedFieldKey];
}
And then for whatever reason, the date just wont save in the app, and the compiler throws this error:
The Debugger has exited with status 0. [Session started at 2009-12-02 09:51:26 -0700.] 2009-12-02 09:51:47.342 CoreDataBooks[17981:20b] * -[__NSCFDate length]: unrecognized selector sent to instance 0x3e79850 2009-12-02 09:51:47.343 CoreDataBooks[17981:20b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSCFDate length]: unrecognized selector sent to instance 0x3e79850'
Probably just a quick fix, I am hoping I was at least in the right hemisphere as far as the code goes, thanks again for any help or insight you have time to offer.