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

  • Home
  • SEARCH
  • 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 6814305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:40:25+00:00 2026-05-26T20:40:25+00:00

For example: I have two entities named Project and Todo where a project has

  • 0

For example:

I have two entities named Projectand Todo where a project has many todos (to-many relationship) and each todo has one Project(see image).

CoreData setup of entities

In my ViewController.h I have something like:

...
NSArray *projectArray;
NSArray *todosArray;

@property (nonatomic,retain) NSArray *projectArray;
@property (nonatomic,retain) NSArray *todosArray;
...

In my ViewController.m I have something like:

...
@synthesize projectArray,todosArray;
...
self.projectArray = [self fetchRequestForAllProjects];
...

The user has an interface where he is able to select between all different projects. As soon as the user selects a project, the related todo objects have to be set to be loaded and presented.

Question 1: How do I load the set of todos into the todosArray in the best way?

I was doing it like that (also in the ViewController.m):

...
// after deselecting a project entry I reset the todosArray
self.todosArray = nil;
...
//when the user selects a new project I reset the todosArray like this:
self.todosArray = [selectedProject.todos allObjects];
...

But somehow the app very rarely crashes in the last line of code. Is there any problem with my code?

Question 2: Would it be better to use another fetch request for the todos Objects?

UPDATE:

I am using the todosArrayin various methods of the ViewController.m:

(a) get the count of objects,
(b) present each todos entry inside a table view row, and
(c) to identify the selected todo entry (threw row selection)

  • 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-26T20:40:25+00:00Added an answer on May 26, 2026 at 8:40 pm

    Answer #1

    It is best to sort them when you pull everything out of the set into an array. This will keep your user experience consistent:

    NSSet *projectTodoEntities = [mySelectedProject valueForKey:@"todos"];
    NSSortDescriptor *sorter = [[NSSortDescriptor alloc] initWithKey:@"myKey" ascending:YES];
    NSArray *sortedToDos = [projectTodoEntities sortedArrayUsingDescriptors:[NSArray arrayWithObject:sorter]];
    

    Answer #2

    No, fetching is expensive compared to just accessing a relationship. A fetch will hit disk, etc.

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

Sidebar

Related Questions

I have two entities, Class and Student , linked in a many-to-many relationship. When
I have a question about One-To-Many relationship between two tables when there is the
A have two entities. For example timing settings and orders. @Entity public class TimingSettings{
Let's say I have two entities: Physician Credentials And a physician can have many
Here is my problem with simplified example. I have two entities modeled from SQL
I have two tables, entities and components, each with a name and unique ID.
I have two entities, each from a different database and therefore different edmx files.
I want to implement a one-to-many relation using Hibernate (in Java). I have two
Example: I have two shared objects (same should apply to .dlls). The first shared
I have two arrays of animals (for example). $array = array( array( 'id' =>

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.