我有以下谓词,但是在获取请求后我得到了一些非常奇怪的结果。
谓词:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"parkingEndTime > %f",floor(timestamp)];
示例:
这是完整的代码:
+ (NSArray *)getParkedCars {
AppDelegate *myAppDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *ctx = [myAppDelegate getThreadSafeManagedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Car"];
NSTimeInterval timestamp = [[NSDate date] timeIntervalSince1970];
NSLog(@"Parking End Time: %f",floor(timestamp));
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"parkingEndTime > %f",floor(timestamp)];
[request setPredicate:predicate];
NSError *error = nil;
NSArray *result = [ctx executeFetchRequest:request error:&error];
NSLog(@"Fetched request: %@",[result firstObject]);
return result;
}
答案 0 :(得分:0)
通过在比较之前将其转换为NSNumber来修复:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"parkingEndTime > %@",@(floor(timestamp))];