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

  • Home
  • SEARCH
  • 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 7740625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:49:42+00:00 2026-06-01T08:49:42+00:00

I have an application that uses Core Data. I have two data models in

  • 0

I have an application that uses Core Data. I have two data models in the project and I create the ManagedObjectContext by merging the two models. Here the code where I do that:

- (NSManagedObjectModel *)managedObjectModel {
    if (__managedObjectModel != nil) {
        return __managedObjectModel;
    }

    NSURL* entityURL = [[NSBundle mainBundle] URLForResource:@"User_data" withExtension:@"momd"];
    NSManagedObjectModel* entityModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:entityURL]; 

    NSURL* whoURL = [[NSBundle mainBundle] URLForResource:@"WHO_data" withExtension:@"momd"];
    NSManagedObjectModel* whoModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:whoURL];

    NSArray* models = [NSArray arrayWithObjects:entityModel, whoModel, nil];
    __managedObjectModel = [NSManagedObjectModel modelByMergingModels:models];

    return __managedObjectModel; 
}

None of the attributes in my entities are optional and my app crashes when I try to save my managedObjectContext. I believe this is because some of the attributes are not being set. I have overridden awakeFromInsert: for the parent entity:

- (void) awakeFromInsert
{
    [super awakeFromInsert];

    NSString* userCFUUID = [[NSUserDefaults standardUserDefaults]objectForKey:@"device_identifier"];

    if ( userCFUUID ) {
        [self cfuuid:userCFUUID];
    } else {
        [NSException raise:NSInvalidArgumentException format:@"Entry: awakeFromInsert: cannot find CFUUID"];
    }

    [self setCreationDate:[NSDate date]]; // the time since Jan 1st 1970 in seconds
    [self setEventDate:[NSDate date]]; 
}

But awakeFromInsert: is never called. I’ve set a breakpoint and stepped through from the statement where I create the NSManagedObject:

LengthEntry *length1 = [NSEntityDescription insertNewObjectForEntityForName:@"LengthEntry" inManagedObjectContext:moc];

Additional fact that may or may not be relavent:
After creating the datamodel containing the problem entity, I used the Xcode feature to automatically create the classes. I then realised that since I had not specified to do otherwise in the model, xcode named the classes in the plural sense (because that’s what I had called them in the model). So, I ended up with “Entries.h” instead of “Entry.h”. I went back and manually changed all the classes and specified in the model the name of the classes.

So, I need to figure out why awakeFromInsert is never called.

  • 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-06-01T08:49:43+00:00Added an answer on June 1, 2026 at 8:49 am

    Out of desperation, I deleted the datamodel and the NSManagedObject classes. I then recreated the model and the classes.

    Now, it works. Something screwy must have happened when I manually changed the names of the classes.

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

Sidebar

Related Questions

I have an application that uses Core Data that has a relationship that I
I have a core data application that uses an NSPredicate in one of its
I have client application that uses WCF service to insert some data to backend
Environment: xcode 3.2.1, document-based core-data application. I have a document-based cocoa app which uses
I have an application that will use Core Data. I've added the Core Data
I have an app in the app store that uses Core Data to persist
I have an application that uses the grails multi-tenant-core plug-in to host multiple versions
I have an application that uses a UITableView to present data that I have
I have a navigation based app that uses Core Data for storage. The schema
I have an application that uses CoreData. I previously had a class named Marker

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.