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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:14:29+00:00 2026-05-16T21:14:29+00:00

When I have a CoreData entity named, say, ‘Book’, which has a one-to-one relationship

  • 0

When I have a CoreData entity named, say, ‘Book’, which has a one-to-one relationship with another entity (‘Bookmark’) would I need to insert both an instance of ‘Book’ and an instance of ‘Bookmark’ into a managed object context, and manually assign the relationship?

If I perform the following code to instantiate an instance of ‘Book’…

Book *book = [NSEntityDescription insertNewObjectForEntityForName:@"Book" inManagedObjectContext:managedObjectContext];

Can I, or can I not, perform the following code to retrieve its bookmark without inserting an instance of ‘Bookmark’ into the same managed object context?

book.bookmark;

Will CoreData allocate a new instance of ‘Bookmark’ for me?

Before you ask me to try this and see for myself: I have. I’m either doing something wrong, or I’m meant to instantiate both instances of ‘Book’ and ‘Bookmark’ and assign the relationship manually. In my testing, the relationship has ‘optional’ unticked but is not attached to anything. Upon invoking the getter ‘bookmark’ on a ‘book’ instance, I receive ‘nil’.

I’d like to be able to use my code above, as it will allow my controller objects to deal with the managed object context, while my model objects can ignore it entirely. From what I’ve read of CoreData, this seems to be the intended implementation. Please correct me if I’m wrong.

  • 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-16T21:14:30+00:00Added an answer on May 16, 2026 at 9:14 pm

    In my experience you have to create both entities and create the relationship yourself first.

    something like this should be what you need:

    Bookmark *bookmark = [NSEntityDescription insertNewObjectForEntityForName:@"Bookmark" inManagedObjectContext:managedObjectContext];
    [book setBookmark: bookmark];  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using CoreData, I have an entity Bookmark, that has an to-many relationship named 'tags'
I have a core data entity named Folder. Each Folder has a 1-to-many relationship
I have a couple of views which present data from a CoreData entity in
I have an entity in core data that has 2 Attributes. One that is
Let's say I have a table named Coffee Mug and a relationship to many
I have problems with my coredata sqlite DB, which hosts a book DB. After
I have a Core Data entity which needs a gender property. I just need
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
In my core data model I have a Person entity that has a to

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.