AFIncrementalStore を使用して、非常に単純な NSIncrementalStore の例を設定しています。
アイデアは、AppDelegate で NSManagedObjectContext をセットアップし (Apple が提供する通常のテンプレートを使用し、私の IncrementalStore に変更を加えて)、述語またはソート記述子なしでフェッチを実行し、NSLog を 1 つのフェッチされたエンティティ オブジェクトにすることです。
エンティティ属性を要求するまで、すべてがうまく機能します。次のメッセージでクラッシュします。
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 が表示されます。Web サービスは正しいデータを返してくれます。
私の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);
}
このコードを作成して、私が求めている属性を返す方法についてのアイデアはありますか?