我从 CoreData 获取中创建了一个 NSArray,如下所示:
self.farSiman = [self.managedObjectContext executeFetchRequest:request error:&error];
在表格视图中,我使用此代码来获取我的自定义对象:
Holiday *holiday = [self.dates objectAtIndex:indexPath.row];
cell.nameLabel.text = holiday.name;
但是我现在在另一个视图控制器中,试图在 mapkit 上绘制数据,所以在绘图方法中我最初这样做是因为我从 plist 文件中获取了一个数组。但是现在我的数组是自定义的 Holiday 对象,所以这不再起作用了:
NSLog(@"dictionary is %@", self.farSiman);
for (NSDictionary * dict in self.farSiman) {
NSNumber * latitude = [dict objectForKey:@"latitude"];
NSNumber * longitude = [dict objectForKey:@"longitude"];
NSString * storeDescription = [dict objectForKey:@"name"];
NSString * address = [dict objectForKey:@"address"];
NSLog(@"logging location %@", storeDescription);
CLLocationCoordinate2D coordinate;
coordinate.latitude = latitude.doubleValue;
coordinate.longitude = longitude.doubleValue;
MyLocation *annotation = [[MyLocation alloc] initWithName:storeDescription address:address coordinate:coordinate];
[_mapView addAnnotation:annotation];
}
我的字典日志打印出这个:
dictionary is (
"<Holiday: 0x838bc80> (entity: Holiday; id: 0x838ca60 <x-coredata://E41B0CCD-2F03-4C4F-B054-18537096771C/Holiday/p1> ; data: <fault>)",
"<Holiday: 0x838e330> (entity: Holiday; id: 0x838ca70 <x-coredata://E41B0CCD-2F03-4C4F-B054-18537096771C/Holiday/p2> ; data: <fault>)"
这意味着它是一系列假日对象。
由于我使用枚举而不是传统的,如何在我的 for 循环中获取每个对象for i = 0; i<count; i++
?