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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:13:17+00:00 2026-05-29T06:13:17+00:00

NSManagedObject *parent = [NSEntityDescription insertNewObjectForEntityForName:@Parent inManagedObjectContext:self.managedObjectContext]; NSManagedObject *child = [NSEntityDescription insertNewObjectForEntityForName:@Child inManagedObjectContext:self.managedObjectContext]; [child setValue:parent

  • 0
NSManagedObject *parent = [NSEntityDescription insertNewObjectForEntityForName:@"Parent" inManagedObjectContext:self.managedObjectContext];
NSManagedObject *child = [NSEntityDescription insertNewObjectForEntityForName:@"Child" inManagedObjectContext:self.managedObjectContext];
[child setValue:parent forKey:@"parent"];

That doesn’t seem to work for me, but I can do something like this:

[child setValue:"John" forKey:@"name"];

Thanks for the help!

  • 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-29T06:13:18+00:00Added an answer on May 29, 2026 at 6:13 am

    If the relationship has been defined in the ManagedObjectModel you can use

    [parent setValue:child forKey:@"childObject"];
    

    This code example assumes that your Entity Parent has a relationship attribute set called childObject.

    enter image description here

    To use the . accessor for a property of a NSManagedObject you will need to subclass it.
    Select your Entity and click Create NSManagedObject Subclass from the Editor Menu

    EditorMenu

    Then instead of Creating your objects as NSManagedObjects, create them as Parent and Child classes

    #import "Parent.h"
    #import "Child" 
    Parent *parent = [NSEntityDescription insertNewObjectForEntityForName:@"Parent" inManagedObjectContext:self.managedObjectContext];
    Child *child = [NSEntityDescription insertNewObjectForEntityForName:@"Child" inManagedObjectContext:self.managedObjectContext];
    parent.childObj = child;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've noticed that this line is causing problem NSManagedObject *newContact = [NSEntityDescription insertNewObjectForEntityForName:@Contacts inManagedObjectContext:context];
I am creating a NSManagedObject by using the insertNewObjectForEntityForName convience message on NSEntityDescription .
I have an NSManagedObject who has a one to many relationship with the parent
I have a ConfiguracaoDaApp class in my project that is a NSManagedObject subclass. I
I found this wonderful NSManagedObjectID. This would be very good for referencing an Entity/NSManagedObject/NSEntityDescription,
I have an NSManagedObject that has a to-many relationship to another NSManagedObject. During creation
NSManagedObject *entryObj = [self.fetchedResultsController objectAtIndexPath:indexPath]; entryObj consists of four String attributes. If I NSLog
I have a CoreData NSManagedObject subclass, TextNarration, that has an attribute of type NSString,
I have a subclassed NSManagedObject that conforms to the MKAnnotation protocol and it has
I'm working on an app where there are two different NSManagedObject types that might

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.