我有一个实体Person
和一个属性personId
(personId是唯一的)
我怎样才能找到那个有max personId的人?
(我想要的是人本身,而不是财产的价值)
我有一个实体Person
和一个属性personId
(personId是唯一的)
我怎样才能找到那个有max personId的人?
(我想要的是人本身,而不是财产的价值)
将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;