1
我創建一個NSArray從CoreData取像這樣:我如何通過自定義的一個NSArray循環對象
self.farSiman = [self.managedObjectContext executeFetchRequest:request error:&error];
在的tableview我用這個代碼,讓我的自定義對象:
Holiday *holiday = [self.dates objectAtIndex:indexPath.row];
cell.nameLabel.text = holiday.name;
但是,我現在在另一個viewcontroller,試圖繪製一個mapkit上的數據,所以在繪圖方法我原來這樣做是因爲我從一個plist文件中獲取數組。但現在我的陣列是定製的假日的對象,因此這不工作了:
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++
?