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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:56:29+00:00 2026-05-13T10:56:29+00:00

I have an NSArrayController, companiesController bound to a top level Core Data entity, Companies

  • 0

I have an NSArrayController, companiesController bound to a top level Core Data entity, Companies.

A Company has many Department‘s, and a Department has many Employee; these are represented by the 1-to-many relationships, departments and employees.

Based on the attribute salary of an Employee I thought I could dynamically do this for filtering based on salary inside a UI-called method:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY departments.employees.salary < %@", [NSNumber numberWithInt:23000]];
[companiesController setFilterPredicate:predicate];

Alas, this gives me the error: -[NSCFSet compare:]: unrecognized selector sent to instance.

  • 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-13T10:56:29+00:00Added an answer on May 13, 2026 at 10:56 am

    Multiple to-many keys are not allowed in this case.

    Instead, you could do the following:

    1. Modify the data model by adding a “filter” flag (Boolean) attribute to the Department entity.
    2. Create a method to: fetch all the Department objects, set the filter flag to YES for the departments that meet the criteria of the second half of your predicate, set the filter flag to NO for the other departments, and save.
    3. Use the filter flag in the Company predicate.

    Code changes (step 3):

        //NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY departments.employees.salary < %@", [NSNumber numberWithInt:23000]];
        [self setDeptFilter:23000];
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY depts.filter == YES"];
        [companiesController setFilterPredicate:predicate];
    

    And the new method (step 2):

    - (void)setDeptFilter:(NSUInteger)salary {
        NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    
        NSEntityDescription *entity = [NSEntityDescription entityForName:@"Department" inManagedObjectContext:self.managedObjectContext];
        [fetchRequest setEntity:entity];
    
        NSError *error = nil;
    
        // fetch all Department objects
        NSArray *array = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
    
        [fetchRequest release];
    
        if (error) {
            NSLog(@"Error fetching Departments %@, %@", error, [error userInfo]);
            abort();
        }
    
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY emps.salary < %@",[NSNumber numberWithInteger:salary]];
        NSArray *filterArray = [array filteredArrayUsingPredicate:predicate];
    
        // set filter flag to YES for the departments that meet the criteria
        for (Department *dep in filterArray) {
            dep.filter = [NSNumber numberWithBool:YES];
        }
    
        NSMutableArray *diffArray = [array mutableCopy];
        [diffArray removeObjectsInArray:filterArray];
    
        // set filter flag to NO for the departments that do NOT meet the criteria
        for (Department *dep in diffArray) {
            dep.filter = [NSNumber numberWithBool:NO];
        }
    
        [diffArray release];
    
        // save
        if ([self.managedObjectContext hasChanges] && ![self.managedObjectContext save:&error]) {
            NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
            abort();
        } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 287k
  • Answers 287k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I don't know anything about jCarouselLite, but in your style,… May 13, 2026 at 5:03 pm
  • Editorial Team
    Editorial Team added an answer Try NSSuperscriptAttributeName with a negative value. Failing that, the hard… May 13, 2026 at 5:03 pm
  • Editorial Team
    Editorial Team added an answer This works fine: >>> class MyThread(threading.Thread): ... def __init__(self): ...… May 13, 2026 at 5:03 pm

Related Questions

I have an NSTableView bound to an NSArrayController , which is bound to an
I have an NSView subclass which is bound to the arrangedObjects of an NSArrayController
Lets say I have an NSArrayController which contains items each with netCost and netProfit
I'm seeing some quirky behaviour with Cocoa's KVC/KVO and bindings. I have an NSArrayController
I have an application using Core Data and bindings. I want to have an

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.