我想要一份我用核心数据存储的唯一联系人列表。
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Post" inManagedObjectContext:[self managedObjectContext]];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity:entityDescription];
NSDictionary *entityProperties = [entityDescription propertiesByName];
[request setPropertiesToFetch:[NSArray arrayWithObject:[entityProperties objectForKey:@"contactID"]]];
[request setReturnsDistinctResults:YES];
NSError *error = nil;
NSMutableArray *retValue = [[[self.managedObjectContext executeFetchRequest:request error:&error] mutableCopy] autorelease];
无论是否有setPropertiesToFetch,结果总是相同的,所以我猜它有问题,但我无法弄清楚它是什么。 有人能帮助我吗?
答案 0 :(得分:2)
您是否将抓取结果类型设置为NSDictionaryResultType
?文档说setPropertiesToFetch:
仅在结果类型== NSDictionaryResultType
.N