iphone - 核心数据 - 如何获取具有最大值属性的实体

标签 iphone objective-c ios core-data nsfetchedresultscontroller

我有一个实体 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/

相关文章:

ios - 更改 iOS 框架的导入

ios - 在 Swift 3 中提取数据对象的片段

iphone - 可以从 iPhone 和 Android 应用程序安全访问哪些常见后端?

iphone - 你如何枚举一组 block ?

iOS Obj-C 将字节数组转换为 plist 到字符串

ios - 如何保持 UISearchBar 的占位符与搜索图标左对齐

objective-c - 正确使用FMDB/内存

ios - dyld : Symbol not found: _OBJC_CLASS_$_GTMMIMEDocument after migrating to Swift 4. 2 和 Firebase 5.8

iphone - 具有核心显卡的图像效果

iphone - 我想列出一个单词列表,但是我不能选择如何存储它。