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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:31:58+00:00 2026-05-27T17:31:58+00:00

I have tried to find apple documentation/tutorials out there on how to let a

  • 0

I have tried to find apple documentation/tutorials out there on how to let a user dynamically add an object and apply the necessary relationship, but need some help with what tutorials are good or what apple documentation will help.

An example of my Core Data problem: 2 Entities of Photographer and Photo, where there is a 1-to-Many relationship between a Photographer and Photo. When the user adds a Photo, I need to be able to specify which Photographer took that Photo.

  • 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-27T17:31:59+00:00Added an answer on May 27, 2026 at 5:31 pm

    So first you’ll create a new entity for photo:

        NSManagedObject *photoObject = [NSEntityDescription 
               insertNewObjectForEntityForName:[entity name]
                        inManagedObjectContext:context];    
    

    The NSManagedObject can be replaced with your Photo object or w/e if you have a subclass made.
    You will set all the attributes for it. To set the photographer you will set it as you would any other attribute. If you don’t have a reference for the Photographer, you can query it like this:

        NSFetchRequest *query = [[NSFetchRequest alloc] initWithEntityName:@"Photographer"];
        [query setPredicate:[NSPredicate predicateWithFormat:@"id == %@", photographerId]];
        NSArray *queryResults = [context executeFetchRequest:bcQuery error:&error];
    

    Your query result will have the photographer object. You can then set it on your photoObject as any other attribute and the link will be created automatically.

         [photoObject setPhotographer:[queryResults objectAtIndex:0]];
    

    or if you are using NSManagedObject:

        [photoObject setValue:[queryResults objectAtIndex:0] forKey:@"photographer"];
    

    The cool thing with CoreData is that it is relational. You can’t really think of it as a typical DBMS. You create object and set relationships between them in a very object-oriented way. There is not primary-key/foreign-key to take care of, that is all done in the background by CoreData.

    EDIT:

    You can choose to create a subclass of NSManagedObject to more easily access attributes and relationships for your entity. Make sure to specify this subclass in the CoreData model explorer; in the sidebar, you will change the “class” field to your new subclass.

    Here is an example of a NSManagedObject subclass:

    //Interface
    @interface Photo : NSManagedObject
    
    #pragma mark - Attributes
    
    @property (nonatomic, strong) NSNumber *id;
    @property (nonatomic, strong) NSString *name;
    
    #pragma mark - Relationships
    
    @property (nonatomic, strong) NSSet     *someToManyRelationship;
    @property (nonatomic, strong) Photographer *photographer;
    
    @end
    
    //Implementation
    @implementation Photo
    
    @dynamic id, name;
    @dynamic someToManyRelationship, photographer;
    
    @end
    

    Hope this helps!

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

Sidebar

Related Questions

I have tried to find some decent documentation on traversing in jQuery, but have
I have tried to find how to create DLL-s on linux using google, but
I have tried to do some reading about it, but I failed to find
I have tried rectifying the code below. But I am not able to find
Trying to find the sqlserver adapter for rails on windows. I have tried getting
Over the years, I have tried many times to find a good, easy to
I have an address database and I tried to find latitude and longitude using
I tried to find an easy solution for the following. I have a main
I've looked at the documentation but I couldn't find if there was a method
Currently I have a loop that tries to find an unused filename by adding

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.