我正在使用 AFIncrementalStore 设置一个非常简单的 NSIncrementalStore 示例。
这个想法是在 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);
}
关于如何使这段代码返回我要求的属性的任何想法?