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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:02:21+00:00 2026-05-26T09:02:21+00:00

Im my iPhone project, I have a data model with 2 objects: Profile and

  • 0

Im my iPhone project, I have a data model with 2 objects: Profile and Contact. They are related to each other, with 1 Profile having many Contacts. Here is what I’m not sure about:

What is the right way to assign a Profile to a Contact when I add the Contact to the database?

I know how to add the contact to the database, but I need to know the right way to add the profile.

self.moc = [((AppDelegate *)[[UIApplication sharedApplication] delegate]) managedObjectContext];
Contact *contact = [NSEntityDescription insertNewObjectForEntityForName:@"Contact" inManagedObjectContext:self.moc];
contact.recordID = recID;
contact.profile = ????????
NSError *err = nil;
[self.moc save:&err];

Do I need to fetch the Profile first? Do I use a separate managedObjectContext, or the same one?

I have the first name of the profile, which I know I can use to fetch it like this:

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
self.moc = [appDelegate managedObjectContext];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(firstName like %@)", appDelegate.currentProfile];
Profile *fetchedData = (Profile *)[NSEntityDescription entityForName:@"Profile" inManagedObjectContext:self.moc];

I think I could do it like this, but if somebody could give me a code block with the best practice, that would be great. Thanks!

  • 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-26T09:02:22+00:00Added an answer on May 26, 2026 at 9:02 am

    You fetch the profile first, you can use the same MOC. Then just assign it to the profile property on the Contact.

    [NSEntityDescription entityForName:@"Profile" inManagedObjectContext:self.moc] is not returning a Profile object though. It returns an entity description.

    + (NSEntityDescription *)entityForName:(NSString *)entityName inManagedObjectContext:(NSManagedObjectContext *)context

    You need to use a fetch request on the MOC. Checkout this:

    http://cocoawithlove.com/2008/03/core-data-one-line-fetch.html

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

Sidebar

Related Questions

I have to make an iPhone project that can process video data in realtime.
I have a small iPhone Project with a UITextView on my View, designed in
I have made a ViewController in XCode for an iPhone project I'm working on,
I have added the <QuartzCore/QuartzCore.h> to my Frameworks folder in my iPhone project and
In my project (iPhone app) I have a nice webview to allow users to
I have a project that was developed for iPhone OS 2.0. I am transforming
I began an iPhone project the other day with a silly development code name,
I'd like to add core data to an existing iPhone project, but I still
I am working on a iphone/Ipod touch project involving saving and fetching data from
So I have two view controllers in my iphone project - one of them

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.