OStack程序员社区-中国程序员成长平台

标题: ios - 根据 coredata 中的属性名称获取唯一对象 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:30
标题: ios - 根据 coredata 中的属性名称获取唯一对象

我在 coredata 中有实体employee_detail

name | rate | factor |
_______|______|________|
John   |  3.2 |    4   |
Betty  |  5.5 |    7   |
Betty  |  2.1 |    2   |
Betty  |  3.1 |    2   |
Edward |  4.5 |    5   |
John   |  2.3 |    4   |

我想要基于属性名称的唯一对象

O/P 应该是

name | rate | factor |
_______|______|________|
John   |  3.2 |    4   |
Betty  |  5.5 |    7   |
Edward |  4.5 |    5   |



Best Answer-推荐答案


NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName"employee_detail"];
NSEntityDescription *entity = [NSEntityDescription entityForName"employee_detail" inManagedObjectContext:self.managedObjectContext];

fetchRequest.resultType = NSDictionaryResultType;
fetchRequest.propertiesToFetch = [NSArray arrayWithObject:[[entity propertiesByName] objectForKey"name"]];
fetchRequest.returnsDistinctResults = YES;

NSArray *dictionaries = [self.managedObjectContext executeFetchRequest:fetchRequest error:nil];
NSLog (@"names: %@",dictionaries);

关于ios - 根据 coredata 中的属性名称获取唯一对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30755509/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4