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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:37:53+00:00 2026-05-21T12:37:53+00:00

I have a question about NSFetchedResultController updating problem. As you may have already known,

  • 0

I have a question about NSFetchedResultController updating problem.

As you may have already known, if I fetch all items and set the NSFetchedResultController’s delegate, then if the data has been changed, the controller will catch the changes and auto update its objects.

But if I fetch items with NSPredicate, it does not catch any change nor its objects. Can someone tell me why?

Here is the codes with NSPredicate set.

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:self.globalContext];
    [fetchRequest setEntity:entity];
    [fetchRequest setFetchBatchSize:200]; 

    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Department" ascending:YES selector:nil];

    NSArray *descriptors = [NSArray arrayWithObjects:sortDescriptor, nil];
    [fetchRequest setSortDescriptors:descriptors];
    [sortDescriptor release];

    NSPredicate *pred = [NSPredicate predicateWithFormat:@"Department IN %@",departmentArray];
    [fetchRequest setPredicate:pred];

    self.resultsController = [[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.globalContext sectionNameKeyPath:@"Department" cacheName:@"Root"] autorelease];
    self.resultsController.delegate = self;

    [self.resultsController performFetch:nil];
    [fetchRequest release];

In the code, I set the @”Department” as the sectionNameKeyPath, and I only need “Person” items from a number of Department (departmentArray), not all Departments.

If I remove the NSPredicate from the NSFetchRequest, then each time a person item with even a new department is inserted, the resultsController will know and trigger the delegate.

But If I keep the NSPredicate, the resultsController won’t be able to know any change. For example:

My department array has the following names: @”Sales”, @”Human Resources”.

Initially, there is no persons from @”Sales” in the Core Data. I do a fetch,then only persons from @”Human Resources” are obtained.

Then a person from @”Sales” is inserted, I think the resultsController should automatically update, right? Because the new person with @”Sales” fits to the NSPredicate, right?

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-21T12:37:54+00:00Added an answer on May 21, 2026 at 12:37 pm

    The predicate is not dynamic and does not respond to changes in the departmentArray after the predicate has been created. As far as the predicate is concerned, departmentArray only ever contains Human Resources. Further, the fetch request is likewise static and does not change so even if the predicate did change, the fetch request would not.

    If you change the departmentArray, you need to generate a new fetch request for the fetched results controller.

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

Sidebar

Related Questions

I have question about the combo box. The problem I'm having is with the
I have question about NSView: Imagine a Custom View where the mouseDown, mouseDrag and
I have a question about using streams in .NET to load files from disk.
I have a question about best practices regarding how one should approach storing complex
I have a question about locking. This doesn't have to be only about record
I have a question about how to deploy WPF application into a PC without
I have a question about using os.execvp in Python. I have the following bit
I have a question about using new[] . Imagine this: Object.SomeProperty = new[] {string1,
I have a question about this question . I posted a reply there but
I have a question about tables in MySQL. I'm currently making a website where

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.