title: Filter a DADataTable using a NSPredicate with a NSDate
body: <p>I have an issue with using a <code>NSPredicate</code> to filter a <code>DaDataTable</code> using a <code>NSDate</code>, when I apply the <code>NSPredicate</code> to the <code>DaDataTable</code> rows and I store the result in a <code>NSMutableArray</code> it always contains zero rows.</p>
  
  <p>Let’s say I have the following table</p>
  
  <pre><code>Field1
  2013-04-10 05:00:00 +0000
  2013-04-10 05:00:00 +0000
  2013-04-11 05:00:00 +0000
  2013-04-11 05:00:00 +0000
  2013-04-12 05:00:00 +0000
  </code></pre>
  
  <p>And the <code>NSPredicate</code> is…</p>
  
  <pre><code>NSPredicate *predicate = [@"" stringByAppendingFormat:@"(%@ == ‘%@‘)”, filter.realField, filter.value];
  </code></pre>
  
  <p>where <code>filter.realField</code> is <code>Field1</code> and <code>filter.value</code> is the <code>NSDate</code> I want to use, let’s say it’s <code>2013-04-10 05:00:00 +0000</code></p>
  
  <p>In theory, it should return a <code>NSMutableArray</code> with two rows. But as I said early, it always returns an array with zero rows…</p>
  
  <p>Here is the code that uses the predicate to filter the <code>DADataTable</code> (<code>dataTable</code>) which contains the table I mentioned early…</p>
  
  <pre><code>    if (predicate) {
          NSMutableArray *array = [NSMutableArray arrayWithArray:[dataTable rowsFilteredUsingPredicate:predicate]];
          if (array.count &gt; 0) {
              [dataTable setRows:array];
              return YES;
          }
          else {
              //Alert that says the array is empty…
              return NO;
          }
      }
      else {
          return NO;
      }
  </code></pre>
  
  <p>And if I try to set a range between two <code>NSDate</code>, one that contains the day I choose to use in the predicate (<code>2013-04-10 05:00:00 +0000</code>) and one with the next day of that date (<code>2013-04-11 05:00:00 +0000</code>). To obtain the next day i used the code of Zaky German in <a href="https://stackoverflow.com/questions/5067785/how-do-i-add-1-day-to-a-nsdate">How do i add 1 day to a NSDate?</a></p>
  
  <p>but in this case I changed the <code>NSPredicate</code> like this</p>
  
  <pre><code>NSPredicate *predicate = [@"" stringByAppendingFormat:@"(%@ &gt;= ‘%@‘) AND (%@ &lt;= ‘%@‘)”, filter.realField, filter.value, filter.realField, nextDay];
  </code></pre>
  
  <p>it gives me the following error.</p>
  
  <pre><code>-[__NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x7fd50940
  *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x7fd50940'
  
  *** First throw call stack:
  (
  0   CoreFoundation                      0x04aed946 __exceptionPreprocess + 182
  1   libobjc.A.dylib                     0x04776a97 objc_exception_throw + 44
  2   CoreFoundation                      0x04af55c5 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
  3   CoreFoundation                      0x04a3e3e7 ___forwarding___ + 1047
  4   CoreFoundation                      0x04a3dfae _CF_forwarding_prep_0 + 14
  5   CoreFoundation                      0x04a1b714 -[NSDate compare:] + 68
  6   Foundation                          0x041a8d12 -[NSComparisonPredicateOperator performPrimitiveOperationUsingObject:andObject:] + 413
  7   Foundation                          0x0416e913 -[NSPredicateOperator performOperationUsingObject:andObject:] + 308
  8   Foundation                          0x0416deb5 -[NSComparisonPredicate evaluateWithObject:substitutionVariables:] + 345
  9   Foundation                          0x0419eb26 -[NSCompoundPredicateOperator evaluatePredicates:withObject:substitutionVariables:] + 254
  10  Foundation                          0x0419e99c -[NSCompoundPredicate evaluateWithObject:substitutionVariables:] + 292
  11  Foundation                          0x0416dd54 -[NSPredicate evaluateWithObject:] + 48
  12  Foundation                          0x0416dcd3 _filterObjectsUsingPredicate + 437
  13  Foundation                          0x0416da7b -[NSArray(NSPredicateSupport) filteredArrayUsingPredicate:] + 328
  14  iSIREGob                            0x00d47174 -[DADataTable rowsFilteredUsingPredicate:] + 68
  15  iSIREGob                            0x000ed291 -[DataSource doSearch:campoAFiltrar:VasABuscar:] + 1537
  16  iSIREGob                            0x000cc12b -[SireGenListGetBrowse searchBarSearchButtonClicked:] + 587
  17  UIKit                               0x0329d159 -[UISearchBar(UISearchBarStatic) _searchFieldReturnPressed] + 84
  18  libobjc.A.dylib                     0x0478c7cd -[NSObject performSelector:withObject:withObject:] + 84
  19  UIKit                               0x02f3b23d -[UIApplication sendAction:to:from:forEvent:] + 99
  20  UIKit                               0x02f3b1cf -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
  21  UIKit                               0x0306ee86 -[UIControl sendAction:to:forEvent:] + 69
  22  UIKit                               0x0306f2a3 -[UIControl _sendActionsForEvents:withEvent:] + 598
  23  UIKit                               0x03079a37 -[UIFieldEditor insertText:] + 275
  24  UIKit                               0x0378f46a -[UITextField insertText:] + 60
  25  UIKit                               0x031802ab -[UIKeyboardImpl insertText:] + 107
  26  UIKit                               0x0317c61d -[UIKeyboardImpl performKeyboardOutput:] + 551
  27  UIKit                               0x0317c27a __55-[UIKeyboardImpl handleKeyboardInput:executionContext:]_block_invoke_2 + 157
  28  UIKit                               0x037b40a2 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 404
  29  libobjc.A.dylib                     0x0478c771 -[NSObject performSelector:withObject:] + 70
  30  Foundation                          0x04164f20 __NSThreadPerformPerform + 330
  31  CoreFoundation                      0x04a111df __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
  32  CoreFoundation                      0x04a06ced __CFRunLoopDoSources0 + 253
  33  CoreFoundation                      0x04a06248 __CFRunLoopRun + 952
  34  CoreFoundation                      0x04a05bcb CFRunLoopRunSpecific + 443
  35  CoreFoundation                      0x04a059fb CFRunLoopRunInMode + 123
  36  GraphicsServices                    0x056e024f GSEventRunModal + 192
  37  GraphicsServices                    0x056e008c GSEventRun + 104
  38  UIKit                               0x02f398b6 UIApplicationMain + 1526
  39  iSIREGob                            0x00037c8d main + 141
  40  libdyld.dylib                       0x05255ac9 start + 1
  41  ???                                 0x00000001 0x0 + 1
  )
  libc++abi.dylib: terminating with uncaught exception of type NSException
  </code></pre>
  
  <p>I hope you can help me to solve this, and Thanks in advance!</p>