我希望只显示核心数据获取请求的唯一结果。目前从研究中我看到可以通过使用来实现这一点,NSDictionaryResultType
但我一直在努力让它发挥作用。
我确实尝试使用以下内容,但无法将其正确集成到我的班级中。我不是 100% 确定要放什么,NSArray *distincResults
因为它出现了未使用的变量:
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Routines" inManagedObjectContext:managedObjectContext];
request.entity = entity;
request.propertiesToFetch = [NSArray arrayWithObject:[[entity propertiesByName] objectForKey:@"routinename"]];
request.returnsDistinctResults = YES;
request.resultType = NSDictionaryResultType;
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"routinename" ascending:YES];
[request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
NSError *error = nil;
NSArray *distincResults = [managedObjectContext executeFetchRequest:request error:&error];
// Use the results
有什么建议么?