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 <=, => ,BETWEEN etc. which all did not work I spotted a possibly strange behaviour: My current NSPredicate looks like this :
let pred = NSPredicate(format: "start>= %@",dayBegin);
where dayBegin is set to NSDate();
However when printing the predicate I get:
start >= CAST(475632000.000000, "NSDate")
Evaluating the date above with
let date = NSDate(timeIntervalSince1970: NSTimeInterval(ti));
converts to yesterday, 31 ago.
The result is as expected, all dates in my calendar are shown (since all are above that date).
Trying the solution proposed here I experience the following parsing error:
'Unable to parse the format string "start>= 2016-01-28 00:00:00 +0000"'
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?
Solved:
I was using an Accessor to modify the dates like this:
var startDate: NSDate?{
get {
return NSDate(timeIntervalSince1970: start);
}
set(d){
start = d!.timeIntervalSince1970;
}
}
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.
Now Im using this Accessor:
var startDate: NSDate?{
get {
return NSDate(timeIntervalSinceReferenceDate: start);
}
set(d){
start = d!.timeIntervalSinceReferenceDate;
}
}