coredataを使用してiPhone用のアプリを作成しています。
そのオブジェクトをFavoriteViewControllerに保存したいオブジェクトを持つViewControllerがあります。お気に入りのボタンをクリックして、オブジェクトをmanagedObjectContextに保存したいのですが、次のエラーが発生します。
キャッチされなかった例外「NSInternalInconsistencyException」が原因でアプリを終了しています。理由:「フェッチがすでに進行中の状態で別の操作を実行しようとしました」。*
私のコード:
// Step 1: Create Object
Favorite * newFavorite = (Favorite*)[NSEntityDescription insertNewObjectForEntityForName:@"Favorite" inManagedObjectContext:managedObjectContext];
// Step 2: Set Properties
newFavorite.name = @"Company";
NSLog(@"%@",newFavorite);
// Step 3: Save Object
NSError *error = nil;
if (![newFavorite.managedObjectContext save:&error]) { // this is where the program crash
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
何が間違っているのかわかりません。