我有以下代码,使用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
}
答案 0 :(得分:1)
您还可以获取objectID
并使用类似
[NSPredicate predicateWithFormat:@"objectID IN %@", objectIDs]
答案 1 :(得分:0)
您可以使用[NSManagedObject setValuesForKeysWithDictionary:]