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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:12:09+00:00 2026-06-05T23:12:09+00:00

I am creating a Core Data application where: category entity has the following attributes

  • 0

I am creating a Core Data application where:

category entity has the following attributes

catid:int

catname:string

randomrelation:to-many rel to brandom entity

brandom is another entity having attributes

cid:category entity

no:int

arr:int

My code is the following

category *c=[NSEntityDescription insertNewObjectForEntityForName:@"category" inManagedObjectContext:context];

for (int i=0; i<[arrayofnumbers count]; i++) {
                
    brandom *r=[NSEntityDescription insertNewObjectForEntityForName:@"brandom" inManagedObjectContext:context];
    c.catid=[NSNumber numberWithInt:i];
    r.cid=c;
    r.no=[NSNumber numberWithInt:i+1];
    int objectatindex=[[arrayofnumbers objectAtIndex:i] intValue];
    NSLog(@"object at index:%i",objectatindex);
    r.arr=[NSNumber numberWithInt:objectatindex];
    [set addObject:r];
}

c.randomrelation=r;
NSLog(@"set element count=%i",[set count]);
if (![context save:&error]) {
    NSLog(@"%@",[error localizedDescription]);
}
  • 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-05T23:12:12+00:00Added an answer on June 5, 2026 at 11:12 pm

    I’m not pretty sure if I understood your question.

    About your title question, if you are asking if it is mandatory to store data for different etities that are linked with a relatiosnhip, the answer is it depends.

    You could do that in different times within your application lifecycle if the properties (the relationship) has been declared as optional (1) or you must set them at the same time if you declared is as non-optional (2).

    So, if in the first case (1) if could set you create the category entity and set its relationship randomrelation in a different time. In the second one (2), you need to set both in the same time, since Core Data will give a consistency error.

    Some notes about your model.

    First call the enities like class name, e.g. Category instead of category, and adopt the camel case notation.

    Second, create an inverse relationships from Brandom to Category. Inverse rels allow you to maintain the graph consistency. In your model Category has a to-many rel to Brandom declared as Optional and Brandom has an inverse and non-Optional rel (one-to-one) to Category. This allows you to create a Category with zero or more Brandom but a Brandom cannot “live” without a Category.

    Hope that helps.

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

Sidebar

Related Questions

I am creating an application using Core Data. But When I run my app
I am creating an application, and am using Core Data as my backend data
I have this issue with Core Data. I am creating a core-data-based application, for
I’m creating an application that uses Core Data to store information and uses web
I have a document based application running with core data. The object model has
I'm creating a Core Data model for my application. I would like to be
I've been creating an iPhone App using Core Data. First of all, does it
I'm creating a data model using xcode and core data. It's an object graph,
I started using Core Data for iPhone development. I started out by creating a
E.g. what Use Core Data for storage checkbox option means when creating new Window

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.