Я загружаю список объектов из CoreData следующим образом:
- (NSMutableArray *)loadAllPoisFromCache:(BOOL)includeCustom {
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setReturnsObjectsAsFaults:NO];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"PointOfInterest" inManagedObjectContext:managedObjectContext];
NSSortDescriptor *sort = [[NSSortDescriptor alloc]
initWithKey:@"sortOrder" ascending:YES];
[request setSortDescriptors:[NSArray arrayWithObject:sort]];
[sort release];
if(!includeCustom) {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(custom == %i)",NO];
[request setPredicate:predicate];
}
[request setEntity:entity];
NSError *error = nil;
NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
[request release];
return mutableFetchResults;
}
Сущность "PointOfInterest" является COMPPointOfInterest и имеет связь с сущностью "Location", которая является COMPLocationEntity.
Затем я перебираю результаты:
NSMutableArray *mutableFetchResults = [self loadAllPoisFromCache:YES];
if (mutableFetchResults != nil && [mutableFetchResults count] > 0) {
NSLog(@"NOTIF_PoisLoaded with data from cache");
for (COMPPointOfInterest *aPoi in mutableFetchResults) {
COMPLocationEntity *locBeforePrintingOutPoi = aPoi.locationEntity;
NSLog(@"Loc class before printing out parent POI = %@", [locBeforePrintingOutPoi class]);
NSLog(@"Loaded POI %@ from cache %@ and location %@", aPoi.poiId, [aPoi class], [locBeforePrintingOutPoi class]);
NSLog(@"Loaded POI from cache %@", aPoi);
COMPLocationEntity *locAfterPrintingOutPoi = aPoi.locationEntity;
NSLog(@"Loc class refetched from parent POI after printing out POI = %@", [locAfterPrintingOutPoi class]);
NSNumber *lat2 = locAfterPrintingOutPoi.latitude;
NSLog(@"Lat from refetched loc %@", lat2);
// crash on next line!
NSNumber *lat = locBeforePrintingOutPoi.latitude;
NSLog(@"Lat %@", lat);
}
Теперь, вот где я застрял, если вы запустите это, вывод будет следующим:
2011-01-24 16:35:41.063 NEC Companion[11959:207] NOTIF_PoisLoaded с данными из кэша
2011-01-24 16:35:41.064 NEC Companion[11959:207] Класс Loc перед распечаткой родительского POI = _NSObjectID_48_1
2011-01-24 16:35:41.068 NEC Companion[11959:207] Загрузил POI 1 из кэша COMPPointOfInterest и местоположения _NSObjectID_48_1
2011-01-24 16:35:41.069 NEC Companion[11959:207] POI загружен из кеша (объект: PointOfInterest; id: 0xae19110 ; данные: { cacheDate = "2011-01-24 16:09:26 +0000"; custom = 0; locationEntity = "0xae18ff0"; logoUrl = "http://192.168.37.213/companion/images/mapicons/es"; poiId = 1; sortOrder = 0; })
2011-01-24 16:35:41.071 NEC Companion[11959:207] Класс Loc обновлен из родительской POI после распечатки POI = COMPLocationEntity
2011-01-24 16:35:41.072 NEC Companion[11959:207] Широта из обновленного местоположения 52.460118
2011-01-24 16:35:41.072 NEC Companion[11959:207] - [широта_NSObjectID_48_1]: нераспознанный селектор отправлен в экземпляр 0xae18ff0
Суть моей проблемы в том, что если я возьму атрибут "locationEntity" из POI сразу же, как только начну перебирать список, класс выйдет как _NSObjectID_48_1, затем я сделаю NSLog(@"Loaded POI from cache %@", апои); и после этого я снова получаю атрибут "locationEntity" и получаю правильный класс COMPLocationEntity!
Таким образом, похоже, что вызов метода описания делает что-то, чтобы полностью правильно создать экземпляр POI... но что?
Любая помощь высоко ценится.