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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:06:27+00:00 2026-05-12T08:06:27+00:00

I have now nearly figured out how to Filter a NSTreeController, to do this

  • 0

I have now nearly figured out how to Filter a NSTreeController, to do this I have sub-classed NSManagedObject and added some code to my App Delegate, I have also bound my NSSearchField to the filterPredicate of my App Delegate but I think I need to connect my NSTreeController and NSSearchField in some way to make it work.
Below I have posted all the code I have used so far to try and make it work.


NSManagedObject Sub-Class Header File.

@interface Managed_Object_Sub_Class : NSManagedObject {
    NSArray *filteredChildren; // this should fix the compiler error
}

- (NSArray *)filteredChildren;


@end

NSManagedObject Sub-Class Implementation File.

@implementation Managed_Object_Sub_Class

static char *FilteredChildrenObservationContext;

- (id)initWithEntity:(NSEntityDescription *)entity insertIntoManagedObjectContext:(NSManagedObjectContext *)context {
    if (self = [super initWithEntity:entity insertIntoManagedObjectContext:context]) {
        [[NSApp delegate] addObserver:self forKeyPath:@"filterPredicate" options:0 context:&FilteredChildrenObservationContext];
        [self addObserver:self forKeyPath:@"subGroup" options:0 context:&FilteredChildrenObservationContext];
    }
    return self;
}

// use finalize with GC
- (void)dealloc {
    [[NSApp delegate] removeObserver:self forKeyPath:@"filterPredicate"];
    [self removeObserver:self forKeyPath:@"subGroup"];
    [super dealloc];
}

- (NSArray *)filteredChildren {
    if (filteredChildren == nil) {
        NSPredicate *predicate = [[NSApp delegate] filterPredicate];
        if (predicate)
            filteredChildren = [[[self valueForKey:@"subGroup"] filteredArrayUsingPredicate:predicate] copy];
        else
            filteredChildren = [[self valueForKey:@"subGroup"] copy];
    }
    return filteredChildren;
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    if (context == &FilteredChildrenObservationContext) {
        [self willChangeValueForKey:@"filteredChildren"];
        [filteredChildren release];
        filteredChildren = nil;
        [self didChangeValueForKey:@"filteredChildren"];
    } else {
        [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
    }
}

@end

Code Added To App Delegate Header File

NSPredicate *filterPredicate;

Code Added To App Delegate Implementation File

- (NSPredicate *)filterPredicate {
    return filterPredicate;
}

- (void)setFilterPredicate:(NSPredicate *)newFilterPredicate {
    if (filterPredicate != newFilterPredicate) {
        [filterPredicate release];
        filterPredicate = [newFilterPredicate retain];
    }
}

Search Field Binding

alt text http://snapplr.com/snap/vs9q


This doesn’t work yet, and so that is why I am asking what I need to do from here to make it work, like I said I think I need to connect the NSSearchField and NSTreeController Together in some way.

  • 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-12T08:06:27+00:00Added an answer on May 12, 2026 at 8:06 am

    Again I hav answered my own question, I also hope that this will help other people so they know how to Filter a NSTreeController.

    To make it work from my post above do the following.

    1.For your entity set the Class as your NSManagedObject Sub-Class in my Case JGManagedObject.

    alt text http://dvlp.me/c3k

    2.For your search field in IB set the predicate format to what you want to Filter ( The Property in your entity, for me it is name).

    alt text http://dvlp.me/9k9rw

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

Sidebar

Related Questions

What I have now (which successfully loads the plug-in) is this: Assembly myDLL =
I've been trying to figure out for nearly a week now how to call
After nearly 5 months with this configuration I am now getting a series of:
I'm nearly complete with this, so I have one final bug I need your
I have now 1gb ram at work(i hope that will change soon) and jboss
I have now worked on two different teams that use the Agile/Scrum approach in
I have now seen 2 methods for determining if an argument has been passed
We are trying to implement a REST API for an application we have now.
I asked before about pixel-pushing, and have now managed to get far enough to
I use Delphi for many years, and although I have now moved on to

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.