title: NSPredicate working for more than, but not less than
body: <p>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.</p>
  
  <p>It works fine for the most part, except I cannot get 'less than' queries  to work. Here is the code I am using:</p>
  
  <pre><code>case CriteriaSelectionIsLessThan:
          pred = [NSPredicate predicateWithFormat:@"ANY value.attribute.name == %@ AND ANY value.%@ &lt; %@", [attribute name], keyPath, [[activeValue value] value]];
          break;
  case CriteriaSelectionIsMoreThan:
          pred = [NSPredicate predicateWithFormat:@"ANY value.attribute.name == %@ AND ANY value.%@ &gt; %@", [attribute name], keyPath, [[activeValue value] value]];
          break;
  </code></pre>
  
  <p>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 &lt; 1970, it returns the entire Core Data dataset (unfiltered).</p>
  
  <p>[[activeValue value] value] is an NSNumber.</p>
  
  <p>I can't figure it out for the life of me - the predicates are exactly the same but with one character differing!</p>
  
  <p>Help would be greatly appreciated. If you require any more code/information let me know.</p>
  
  <p>Edit: here's how I map the data type on import from JSON:</p>
  
  <pre><code>[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;
  }
  </code></pre>
  
  <p>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.</p>