I am trying to get the results of my MeterReading entity, which has two properties: timestamp and read. "timestamp" is an NSDate. Now I am trying to get an object with an exact date.
NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"MeterReading" inManagedObjectContext:context]; [request setEntity:entity]; NSLog(@"%f", [self.timestamp timeIntervalSince1970]); NSPredicate *pre = [NSPredicate predicateWithFormat:@"timestamp == %@", self.timestamp]; NSLog(@"%@", pre); [request setPredicate:pre];
Now, self.timestamp is previously passed to another ViewController, the NSLog shows:
+1290264372,210091
NSPredicate Logs
timestamp == CAST (311957172.210091, "NSDate")
First question: why do the two numbers not match?
The second and more important question: in ManagedContext, I have four records with dates. If I use "<=" instead of "==", I get results with a date that is less than the one I passed, including the one I want to have. Why can't I get a single date with the operator "=="? Could this be due to the accuracy of my dates?
Thanks!
objective-c iphone fetch nsdate nspredicate
denbec
source share