我有以下代码,它使用 carparts 从数据库中提取汽车。但是我遇到了重复,所以我启用了具有唯一结果的 NSDictionaryResultsType(我认为这是摆脱重复的唯一方法)。
现在我相信我有一系列字典而不是 Car 对象。如何根据我的结果获取汽车对象?
-(NSArray*) loadCarsFromCoreDataUsingCarParts:(NSMutableArray*)inputCarParts{
NSLog(@"carParts =%@",inputCarParts);
NSFetchRequest *fetchRequest =[[NSFetchRequest alloc]init];
//To find the cars we are using the carParts
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Car" inManagedObjectContext:[self managedObjectContext]];
//sets up fetch request details
[fetchRequest setEntity:entity];
[fetchRequest setPredicate:[self parseSearchObjectsIntoAPredicate:inputCarParts:3]];
[fetchRequest setReturnsDistinctResults:YES];
[fetchRequest setResultType:NSDictionaryResultType];
//Perform fetch
NSError *error;
NSArray *records = [[self managedObjectContext] executeFetchRequest:fetchRequest error:&error];
return records;//i think this is an array of dictionaries
}