我使用AFIncrementalStore設置了一個非常簡單的NSIncrementalStore示例。AFIncrementalStore簡單提取以崩潰終止
這個想法是在AppDelegate中設置一個NSManagedObjectContext(使用Apple提供的普通模板,對IncrementalStore進行更改),執行無謂詞或排序描述符的提取和NSLog獲取的實體對象。
一切工作很好,直到我要求任何實體屬性。它崩潰與以下消息:
2013-07-22 16:34:46.544 AgendaWithAFIncrementalStore[82315:c07] -[_NSObjectID_id_0 eventoId]: unrecognized selector sent to instance 0x838b060
2013-07-22 16:34:46.545 AgendaWithAFIncrementalStore[82315:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_NSObjectID_id_0 eventoId]: unrecognized selector sent to instance 0x838b060'
我的xcdatamodeld設置正確。 NSManagedObject類是在委託上生成和導入的。當我在NSLog之前做一個斷點時,我可以看到提取的對象ID。網絡服務正在給我返回正確的數據。
我的AppDelegate代碼:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
[self.window makeKeyAndVisible];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(remoteFetchHappened:) name:AFIncrementalStoreContextDidFetchRemoteValues object:self.managedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription
entityForName:@"Agenda" inManagedObjectContext:self.managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
fetchRequest.entity = entityDescription;
fetchRequest.predicate = nil;
NSError *error;
[self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
return YES;
}
// Handle the notification posted when the webservice returns objects
- (void)remoteFetchHappened:(NSNotification *)aNotification
{
NSArray *fetchResult = [[aNotification userInfo] objectForKey:@"AFIncrementalStoreFetchedObjectIDs"];
Agenda *agenda = (Agenda *)[fetchResult lastObject];
// THIS IS WHERE IT BREAKS...
NSLog(@"Agenda: %@", agenda.eventoId);
}
如何使這段代碼的任何想法回到我所要求的屬性?
謝謝湯姆。你是絕對正確的。 –