[英]NSFetchRequest for an attribute's max value.The result is different every time
NSFetchRequest for an attribute's max value. NSFetchRequest以获取属性的最大值。
But the result turns to a different one every time. 但是结果每次都变成不同的结果。
This is my code. 这是我的代码。
- (NSInteger)getMaxTimeStamp
{
NSManagedObjectContext *context = [delegate managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:[NSEntityDescription entityForName:@"Relation" inManagedObjectContext:context]];
[fetchRequest setIncludesPropertyValues:NO]; //only fetch the managedObjectID
NSSortDescriptor *sort = [[NSSortDescriptor alloc]
initWithKey:@"ts" ascending:NO];
[fetchRequest setFetchLimit:1];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];
NSError * error = nil;
Relation *relation = [context executeFetchRequest:fetchRequest error:&error].lastObject;
//error handling goes here
if (error) {
NSLog(@"ERROR: %@",[error localizedDescription]);
}
if (relation.ts) {
return (NSInteger)relation.ts;
}else {
return 0;
}
} }
and I looped 10 times for result logs 我为结果日志循环了10次
Could anybody helps me out? 有人可以帮我吗? thx~~
谢谢~~
在数据模型中将ts
类型更改为Date。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.