title: NSPredicate with NSDate in swift
body: <p>I'm currently trying to set up a fetch request to retrieve events from a certain date range (starting with comparing just one date). After trying to create a NSPredicate with different variations of  &lt;=, => ,BETWEEN  etc.  which all did not work I spotted a possibly strange behaviour:
  My current NSPredicate looks like this :</p>
  
  <pre><code>let pred = NSPredicate(format: "start&gt;= %@",dayBegin);
  </code></pre>
  
  <p>where dayBegin is set to NSDate();</p>
  
  <p>However when printing the predicate I get:</p>
  
  <pre><code>start &gt;= CAST(475632000.000000, "NSDate")
  </code></pre>
  
  <p>Evaluating the date above with </p>
  
  <pre><code>let date = NSDate(timeIntervalSince1970: NSTimeInterval(ti));
  </code></pre>
  
  <p>converts to yesterday, 31 ago.</p>
  
  <p>The result is as expected, all dates in my calendar are shown (since all are above that date).</p>
  
  <p>Trying the solution proposed  <a href="https://stackoverflow.com/questions/31397408/coredata-conditionally-fetching-on-nsdate-using-nspredicate-swift">here</a> I experience the following parsing error:</p>
  
  <pre><code>'Unable to parse the format string "start&gt;= 2016-01-28 00:00:00 +0000"'
  </code></pre>
  
  <p>I have also tried comparing the date as a time interval using %d but it  didn't work as well.
  Any ideas whats going wrong?</p>
  
  <p><strong>Solved:</strong></p>
  
  <p>I was using an Accessor to modify the dates like this:</p>
  
  <pre><code>var startDate: NSDate?{
      get {
          return NSDate(timeIntervalSince1970: start);
          }
      set(d){
          start = d!.timeIntervalSince1970;
      }
  }
  </code></pre>
  
  <p>Hence I always stored the days with the wrong reference days and did not notice That it refers to 1st of January 2001 instead of 1970.<br>
  Now Im using this Accessor:</p>
  
  <pre><code>var startDate: NSDate?{
      get {
      return NSDate(timeIntervalSinceReferenceDate: start);
      }
      set(d){
          start = d!.timeIntervalSinceReferenceDate;
      }
  }
  </code></pre>