我有一个实体 Person
具有属性 personId
(personId 是唯一的)
如何获取具有最大 personId 的 Person?
(我想获取人本身而不是属性(property)的值(value))
最佳答案
您将 fetchLimit
设置为 1
并按 personId
降序排序。例如:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Person"];
fetchRequest.fetchLimit = 1;
fetchRequest.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"personId" ascending:NO]];
NSError *error = nil;
id person = [managedObjectContext executeFetchRequest:fetchRequest error:&error].firstObject;
关于iphone - 核心数据 - 如何获取具有最大值属性的实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10398019/