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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:05:28+00:00 2026-06-12T16:05:28+00:00

I’m having a problem fetching results from a Core Data store using predicates. What

  • 0

I’m having a problem fetching results from a Core Data store using predicates. What my application does is fetches results from the store based on one or more predicates and shows you either the results based on all of the predicates or the results based on each predicate.

It works fine for the most part, except I cannot get ‘less than’ queries to work. Here is the code I am using:

case CriteriaSelectionIsLessThan:
        pred = [NSPredicate predicateWithFormat:@"ANY value.attribute.name == %@ AND ANY value.%@ < %@", [attribute name], keyPath, [[activeValue value] value]];
        break;
case CriteriaSelectionIsMoreThan:
        pred = [NSPredicate predicateWithFormat:@"ANY value.attribute.name == %@ AND ANY value.%@ > %@", [attribute name], keyPath, [[activeValue value] value]];
        break;

The code for the ‘more than’ predicate works fine, it returns the data set for the query, such as > 1970 (a year). When I try to filter it using the ‘less than’ predicate, such as < 1970, it returns the entire Core Data dataset (unfiltered).

[[activeValue value] value] is an NSNumber.

I can’t figure it out for the life of me – the predicates are exactly the same but with one character differing!

Help would be greatly appreciated. If you require any more code/information let me know.

Edit: here’s how I map the data type on import from JSON:

[attrib setDataType:[NSNumber numberWithInteger:[[attribute valueForKey:@"type"] integerValue]]];...

// Set the correct data type of the value
switch ([[attrib dataType] integerValue]) {
    case AttributeDataTypeNumber:
        [value setNumberValue:[NSNumber numberWithInteger:[valueForKey integerValue]]];
        break;
    case AttributeDataTypeString:   
        [value setStringValue:(NSString *)valueForKey];
        break;
    case AttributeDataTypeDate: {
        NSDateFormatter *df = [[NSDateFormatter alloc] init];
        [df setDateFormat:@"dd-MM-YYYY"];
        [value setDateValue:[df dateFromString:(NSString *)valueForKey]];
    }
        break;
    case AttributeDataTypeBool:
        [value setBooleanValue:[NSNumber numberWithBool:[valueForKey boolValue]]];
        break;
}

See, the data type in my JSON is guaranteed to be right as I check that before importing it (not in the app). Even when I build a predicate that explicitly says that I want a certain dataType (such as value.attribute.dataType == 1 with 1 being a number in a enum) it still doesn’t work. It’s really bizzarre.

  • 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-06-12T16:05:29+00:00Added an answer on June 12, 2026 at 4:05 pm

    I figured it out! If anyone else has run into this problem, here’s how I fixed it:

    [NSPredicate predicateWithFormat:@"SUBQUERY(value, $val, $val.attribute.name == %@ && $val.%@ < %@).@count > 0", [attribute name], keyPath, [[activeValue value] value]]
    

    I think it’s because it’s a to-many key that has to be matched on more than one criteria. When I was using the ANY keyword, I think this was the culprit for returning the values I didn’t want. Works like a charm now.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
Does anyone know how can I replace this 2 symbol below from the string
I am currently running into a problem where an element is coming back from
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
For some reason, after submitting a string like this Jack’s Spindle from a text
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one 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.