我试图从NSPredicate中获得不同的结果。具有不同属性的NSFetchRequest
我的代码:
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Members" inManagedObjectContext:context];
request.entity = entity;
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"city"
ascending:YES
selector:@selector(caseInsensitiveCompare:)]];
request.predicate = [NSPredicate predicateWithFormat:@"memberDeleted == %@", [NSNumber numberWithBool:NO]];
NSDictionary *properties = [entity propertiesByName];
request.propertiesToFetch = [NSArray arrayWithObject:[properties objectForKey:@"city"]];
request.returnsDistinctResults = YES;
request.fetchBatchSize = 20;
NSFetchedResultsController *frc = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:context
sectionNameKeyPath:nil
cacheName:@"CityCache"];
[request release];
self.fetchedResultsController = frc;
[frc release];
的问题是,结果返回同一城市的许多倍。这个实体有很多成员,每个成员都有一个“城市”属性。
我在做什么错?
感谢,
RL
我也许应该补充一点'NSFetchedResultsController'不是一般的'NSDictionaryResultType'的粉丝。你可能会遇到其他问题,不得不放弃'NSFetchedResultsController'。 – Alex
问题是我不想要结果和NSDictionary。如果没有,我将不得不改变我的一些代码。它可以通过其他方式吗? –
你期待它返回什么对象?核心数据只能返回对象图中实际存在的对象。 – Alex