Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 489623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:49:37+00:00 2026-05-13T01:49:37+00:00

Let me start off by saying Im VERY new to iphone development, but Im

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T01:49:37+00:00Added an answer on May 13, 2026 at 1:49 am

    You don’t have to worry about the key business at least to change the date format here. The copyright property in the book object is automatically changed using the key-business in the EditingViewController.

    So you only have to change the place where that property is displayed.
    In DetailViewController.m, change this method:

    - (NSDateFormatter *)dateFormatter {    
        if (dateFormatter == nil) {
            dateFormatter = [[NSDateFormatter alloc] init];
            [dateFormatter setDateStyle:NSDateFormatterMediumStyle];  //REMOVE
            [dateFormatter setTimeStyle:NSDateFormatterNoStyle];  //REMOVE
        }
        return dateFormatter;
    }
    

    To this:

    - (NSDateFormatter *)dateFormatter {    
        if (dateFormatter == nil) {
            dateFormatter = [[NSDateFormatter alloc] init];
            [dateFormatter setDateFormat:@"EEEE MMMM d"];  //NEW LINE
        }
        return dateFormatter;
    }
    

    Edit: Forgot to mention that the actual display is done in cellForRowAtIndexPath in the same file. But that display code uses a class-level variable dateFormatter so we just modify its initialization.

    Edit #2: You modified the sample code to group the rows by the book copyright date. To modify the date format in the section heading there is probably a more elegant way to do it but here is a crude solution. Modify titleForHeaderInSection in RootViewController.m to this:

    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
        NSString *rawDateStr = [[[fetchedResultsController sections] objectAtIndex:section] name];
    
        //convert default date string to NSDate...
        NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
        [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZ"];
        NSDate *date = [formatter dateFromString:rawDateStr];
    
        //convert NSDate to format we want...
        [formatter setDateFormat:@"EEEE MMMM d"];
        NSString *formattedDateStr = [formatter stringFromDate:date];
    
        return formattedDateStr;
    }
    

    The change above assumes you will only do sections by date. If not, you’ll need to check whether the current grouping is by date otherwise it will try to convert author’s name or title to a date and crash. You may also want to add a check for null/invalid date.

    Edit #3: The copyright field is NSDate which contains both date and time. To group by date only, when the copyright field is edited, set the time part to 00 as follows (in save method in EditingViewController.m):

        // Pass current value to the edited object, then pop.
    if (editingDate) {
        NSDate *pickedDateTime = datePicker.date;
    
        NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
        [formatter setDateFormat:@"yyyy-MM-dd 00:00:00 -0000"];
        NSString *pickedDateStr = [formatter stringFromDate:pickedDateTime];
        pickedDateTime = [formatter dateFromString:pickedDateStr];
    
        [editedObject setValue:pickedDateTime forKey:editedFieldKey];
    }
    

    HOWEVER, since the sample data provided in the example from Apple already includes time in the copyright field, editing or adding one book will not put it in the same group as another group with the same date because the other book still has the time portion in it. If you edit both books and save, it will clear the time in both and they will show in the same group.

    A better solution would be to somehow tell the SortDescriptor to only look at the date portion of copyright only instead of the copyright as-is but I’m not sure how to do this yet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me start off by saying, I'm not new to programming but am very
Let me start off by saying that I am very new to WPF and
First off, let me start by saying that I am totally new to working
Let me start by saying I'm very new to Java and to this site.
Let me start off by saying that I am completely new with WPF (this
Preface Let me start off by saying that I'm a relatively new programmer and
Let me just start off by saying I am very much a beginner and
Let me start off by saying I'm brand new to Android programming. I'm using
Let me start off by saying that I'm pretty new to flex and action
Let me start off by saying I don't want to print only the duplicate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.