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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:00:29+00:00 2026-05-16T04:00:29+00:00

I am using CoreData for an iPhone project and I am stuck trying to

  • 0

I am using CoreData for an iPhone project and I am stuck trying to build a predicate.

My core data entity is

Folder 
   parent  - Point to the folder class parent, can be null and is one to one.
   secure  - An enum that holds the security type.

The problem I have is that I am trying to make it so I don’t show any folder that are in a secure folder.

Right now my predicate looks something like this.

NSPredicate *pred = [NSPredicate predicateWithFormat:@"secure = $@ AND (parent = %@ OR parent.secure = %@)",[NSNumber numberWithInteger:kNoSecurity], [NSNull null], [NSNumber numberWithInteger:kNoSecurity]];

This works find when I only have a chain like folder1 -> folder2 and folder1 is secure. But if I have folder1 -> folder2 -> folder3 (folder2 and folder3 are not secure). Folder3 gets returned because I only check one level up. Is there a way to get the predicate to do the check for a entire chain?

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-16T04:00:29+00:00Added an answer on May 16, 2026 at 4:00 am

    The problem is that this only goes up
    one level. So if I have folder1 ->
    folder2 -> folder3 -> folder4, and
    folder1 is secure. Then folder2 is not
    show but folder3 and folder4 are.

    You can’t recursively walk relationships in predicates because keypaths only describe the relationship between the abstract entities and not the concrete, living managed objects that actually contain the data. An entity graph can be very simple yet generate a vastly complex graph of live objects when populated at runtime. You can’t logically capture the complexity of that live graph with a simple keypath.

    In this case, you have a Folder entity which has a relationship to itself called parent and an attribute of secure. Therefore, a keypath can only describe at most those two properties with path parent.secure. You can’t create a keypath of parent.parent.secure because no such relationship actually exists in the entity graph. Such a path only exist sometimes in the live object graph. It would be logically impossible to hard code a path that might or might not exist depending on the particulars of the data at any given time.

    This type of situation is where the ability to create customized NSManagedObject subclasses really comes in handy. Your Folder entites don’t have to be just dumb data, you can add behaviors to them so that each object can access its own state and return different data as needed.

    In this case, I would recommend adding a transient boolean property named something like hasSecureAncestor. Then create a custom getter method like:

    - (BOOL) hasSecureAncestor{
        BOOL hasSecureAncestor=NO;
        if (self.parent.secure==kNoSecurity) {
            hasSecureAncestor=YES;
        }else {
            if (self.parent.parent!=nil) {
                hasSecureAncestor=self.parent.hasSecureAncestor;
            }else {
                hasSecureAncestor=NO;
            }
        }
        return hasSecureAncestor;
    }
    

    Then just create a predicate to test for “hasSecureAncestor==YES”. The custom accessor will walk an arbitrarily deep recursive relationship looking for a secure ancestor.

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

Sidebar

Related Questions

I'm using Core Data in my first iPhone application and trying to understand NSFetchedResultsController.
I created an iPhone project using the Core Data template. Now when I try
When creating a new project (universal iPhone/iPad) using Core Data, there's the usual appDelegate
I'm integrating coredata into my existing application as given in http://wiresareobsolete.com/wordpress/2009/12/adding-core-data-existing-iphone-projects/ . I'm facing
In core data for the iPhone, I was getting all sorts of errors trying
I'm developing for iphone-sdk 2.2.1 (so no CoreData cry ). So I'm using the
I'm working on my 2nd iPhone app and am curious about Core Data. Time
I have an iPhone app that is using CoreData. I recently made some minor
I'm trying to build a C++ extension for python using swig. I've followed the
Using C# .NET 3.5 and WCF, I'm trying to write out some of the

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.