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 6900467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:32:59+00:00 2026-05-27T07:32:59+00:00

I have a Core Data project with a sort of master entity that holds

  • 0

I have a Core Data project with a sort of “master” entity that holds a year value (int 16) and a few other values. There are a few other “child” entities with many-to-one relationships to this one master. In one of those other entities, I want to set a couple of default values, which are a start and end date. The default values should be the beginning and end of the year assigned to the master entity. So I’ve used this:

- (void) awakeFromInsert {
    int currentYear = [[self valueForKeyPath: @"master.year"] intValue];
    NSString *currentYearStart = [NSString stringWithFormat: @"%d-01-01 00:00:01 +0000", currentYear];
    NSString *currentYearEnd = [NSString stringWithFormat: @"%d-12-31 23:59:59 +0000", currentYear];
    [self setStartDate: [NSDate dateWithString: currentYearStart]];
    [self setEndDate: [NSDate dateWithString: currentYearEnd]];    
}

When I run this, currentYear always ends up being 0, even though the value of master’s “year” attribute is 2011. I’ve tried setting “int currentYear = 2011” and then the code works as expected, so the problem seems to be in the first line. The strange thing is, inside the master entity’s subclass of NSManagedObject, I have lines like:

float total = [[self valueForKeyPath: @"child.@sum.amount"] floatValue];

and this always returns the right amount. I don’t see what the difference is. Can anyone else?

  • 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-27T07:32:59+00:00Added an answer on May 27, 2026 at 7:32 am

    Are you sure that master is set at the time your method is called? Also, the awakeFromInsert docs indicate that you must call [super awakeFromInsert] first.

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

Sidebar

Related Questions

In my core data model I have a Person entity that has a to
I have a project on that uses core data and I had migration implemented
I have a core data model with an entity called clients that is made
I have a project that uses Core Data. When the app runs for the
I have a Core Data entity which needs a gender property. I just need
I have a Core Data based mac application that is working perfectly well until
I have an Core Data Entity with a number of attributes, which include amount(float),
I have a document-based Core Data app. My main Core Data entity has several
I have some trouble with a core data project. I have a NSArrayController with
I have based my app upon the Core Data Books example project Apple provide

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.