我正在尝试UIPickerView
使用 fetch 的结果填充 a。我能够做到。由于有重复,我决定使用下面的代码来获取不同的记录和只需要的属性。该代码工作正常,因为数组array1
&dictlevel1
具有正确的数据(如下所示)。我无法弄清楚如何将其array1
放入选择器视图中?
NSError *error;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Factors" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
[fetchRequest setResultType:NSDictionaryResultType];
[fetchRequest setReturnsDistinctResults:YES];
[fetchRequest setPropertiesToFetch:@[@"level1"]];
self.title = @"Factors";
array1 = [[NSArray alloc] init];
array1 = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
NSDictionary *dictlevel1 = [array1 dictionaryWithValuesForKeys:[NSArray arrayWithObject:@"level1"]];
NSLog(@"%@", array1[1]);
NSLog(@"%@", [dictlevel1 dictionaryWithValuesForKeys:[NSArray arrayWithObject:@"level1"]]);
这是输出NSLog
:
2012-10-23 14:55:47.774 CoreData2[1477:c07] (
{
level1 = "External Combustion Boilers";
},
{
level1 = "Internal Combustion Engines";
},
{
level1 = "Industrial Processes";
},
{
level1 = "Petroleum and Solvent Evaporation";
},
{
level1 = "Waste Disposal";
},
{
level1 = "Stationary Source Fuel Combustion";
},
{
level1 = "Miscellaneous Area Sources";
},
{
level1 = "Mobile Sources";
},
{
level1 = "Solvent Utilization";
},
{
level1 = "Storage and Transport";
},
{
level1 = "Waste Disposal, Treatment, and Recovery";
},
{
level1 = "Natural Sources";
}
)
2012-10-23 14:55:47.775 CoreData2[1477:c07] {
level1 = (
"External Combustion Boilers",
"Internal Combustion Engines",
"Industrial Processes",
"Petroleum and Solvent Evaporation",
"Waste Disposal",
"Stationary Source Fuel Combustion",
"Miscellaneous Area Sources",
"Mobile Sources",
"Solvent Utilization",
"Storage and Transport",
"Waste Disposal, Treatment, and Recovery",
"Natural Sources"
);
}