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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:13:21+00:00 2026-06-01T16:13:21+00:00

So, I’m just getting to really enjoy Core Data, and have started integrating it

  • 0

So, I’m just getting to really enjoy Core Data, and have started integrating it into an app I’m working on. However, I have encountered a problem for which I see no obvious solution, which is making me feel like maybe Core Data’s not the right tool for the job. Here’s the situation: I have a tree of Nodes, each of which may or may not have children. There may be arbitrarily many root Nodes. I have put together the data model using to-many relationships (from Node to Nodes) with to-one inverse relationships. All that is fine.

Now, each Node also has a to-many relationship to Records, which also have an inverse to-one relationship back to the Node. What I want to do is find all Records which have a specific boolean attribute set to true, and are somewhere below a given Node. This was super easy before I was using Core Data — I just walk the tree. However, this is time consuming, and I was hoping that Core Data would give me a way to just make a fetch request which would grab all the Records I want quickly. I can see how to do it (semi) easily if I know the max depth I want to check, but what if I want to go all the way down? What if not all Nodes have children?

Should I just walk the tree as I was doing before?

Is NSFetchRequest even capable of performing such a task?

  • 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-01T16:13:22+00:00Added an answer on June 1, 2026 at 4:13 pm

    This isn’t a core data problem, but a graph problem. You have to do the same searching. However, CoreData can allow you to fault in the objects. So, you have several options, two of which are

    1) Walk the tree. You should be able to use the exact same algorithm you were using with the in-memory tree. CoreData should just fault in the objects. Unless you have an extremely deep tree, you should be fine.

    2) Encode the parent relationship in each record. A fair amount of updating when the tree is updated, but fetches will be quicker.

    The following can be turned into a NSCompoundPredicate and assigned as the fetch predicate… Docs say it works on CoreData, but not for sqllite – try it.

    NSPredicate *nodePredicate = [NSPredicate predicateWithFormat:@"field = %@", value];
    // Use nodePredicate to find ones that match the ones you want to find
    // Then use a block predicate to see if the parent is there.
    NSArray *potential = [context executeFetchRequest:fetchRequest error:&error];
    if (!error) {
        NSPredicate *parentPredicate = [NSPredicate predicateWithBlock:^BOOL(id obj, NSDictionary *bindings) {
            Node *node = obj;
            while (node) {
                if ([node.parent.nodeId isEqualToString:targetId) return YES;
                node = node.parent;
            }
            return NO;
        }];
        NSArray *foundNodes = [potential filteredArrayUsingPredicate:parentPredicate];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I have some data like this: 1 2 3 4 5 9 2 6
I have a jquery bug and I've been looking for hours now, I can't
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.