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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:51:14+00:00 2026-05-20T19:51:14+00:00

My situation is simple: I have some records in my core data store. One

  • 0

My situation is simple: I have some records in my core data store. One of their attributes is a string called “localId”. There’s a point where I’d like to find the record with a particular localId value. The obvious way to do this is with an NSFetchRequest and an NSPredicate. However, when I set this up, the request returns zero records.

If, however, I use the fetch request without the predicate, returning all records, and just loop over them looking for the target localId value, I do find the record I’m looking for. In other words, the record is there, but the fetch request can’t find it.

My other methods in which I use fetch requests and predicates are all working as expected. I don’t know why this one is failing.

I want to do this:

- (void)deleteResultWithLocalID:(NSString *)localId {
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    [request setEntity:[NSEntityDescription entityForName:@"WCAAssessmentResult" inManagedObjectContext:context]];
    [request setPredicate:[NSPredicate predicateWithFormat:@"localId == %@", localId]];
    NSError *error = nil;
    NSArray *results = [context executeFetchRequest:request error:&error];
    NSAssert(error == nil, ([NSString stringWithFormat:@"Error: %@", error]));
    if ([results count]) [context deleteObject:[results objectAtIndex:0]];
    else NSLog(@"could not find record with localID %@", localId);
    [self saveContext];
}

But I end up having to do this:

- (void)deleteResultWithLocalID:(NSString *)localId {
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    [request setEntity:[NSEntityDescription entityForName:@"WCAAssessmentResult" inManagedObjectContext:context]];
    NSError *error = nil;
    NSArray *results = [context executeFetchRequest:request error:&error];
    NSAssert(error == nil, ([NSString stringWithFormat:@"Error: %@", error]));
    for (WCAAssessmentResult *result in results) {
        if ([result.localId isEqualToString:localId]) {
            NSLog(@"result found, deleted");
            [context deleteObject:result];
        }
    }
    [self saveContext];
}

Any clues as to what could be going wrong?

edit

I’ve found that I can use the predicate I’m creating to get the results I expect after the fetch request has been executed. So, the following also works:

- (WCAChecklistItem *)checklistItemWithId:(NSNumber *)itemId {
     NSFetchRequest *request = [[NSFetchRequest alloc] init];
     [request setEntity:[NSEntityDescription entityForName:@"WCAChecklistItem" inManagedObjectContext:context]];
     NSArray *foundRecords = [context executeFetchRequest:request error:nil];
     foundRecords = [foundRecords filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"serverId == %@", itemId]];
     if ([foundRecords count]) {
         return [foundRecords objectAtIndex:0];
     } else {
         NSLog(@"can't find checklist item with id %@", itemId);
         return nil;
    }
}

UPDATE

I’ve come across someone else experiencing this very issue:

http://markmail.org/message/7zbcxlaqcgtttqo4

He hasn’t found a solution either.

Blimey! I’m stumped.

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-20T19:51:15+00:00Added an answer on May 20, 2026 at 7:51 pm

    Hate to say it but the most common cause of these types of problems is simple typos. Make sure that your attribute names and the predicate are the same. Make sure that your property names and the attributes names are the same. If a reference to a property works but a reference to attribute name doesn’t there is probably a mismatch.

    You could test for the latter by comparing the return of:

    [result valueForKey:@"localID"]
    

    … with the return of:

    result.localID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Situation: I have a simple XML document that contains image information. I need to
The situation: I have a pieceofcrapuous laptop. One of the things that make it
I have the following situation I think would be best to show in sample
Here's the situation: I'm developing a simple application with the following structure: FormMain (startup
Situation: text: a string R: a regex that matches part of the string. This
The situation is this: You have a Hibernate context with an object graph that
I have a rather simple multi-threaded VCL gui application written with Delphi 2007. I
Alright here's the situation, I have an application written in the Zend_Framework, that is
This question seems to have been asked before, but I feel like my situation
I hope I am not missing something very simple here. I have done a

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.