これは私のオブジェクトモデルです:
クライアントには多くのプロジェクトを含めることができます(オプション)が、プロジェクトには1つのクライアントのみを含める必要があります(必須)。MemoEntryにはプロジェクトを1つだけ含めることができ(オプション)、同じプロジェクトに異なるMemoEntryを含めることができます(オプション)。
削除時:
- Client.projectsには拒否ルールがあります
- Project.clientには無効化ルールがあります
- Project.memosには拒否ルールがあります
- MemoEntry.projectには無効化ルールがあります
それぞれのTableViewController内のクライアント、プロジェクト、またはMemoEntryの削除時に呼び出されるコード:
// Delete the managed object.
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
[context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];
NSError *error;
if (![context save:&error]) {
// Update to handle the error appropriately.
NSLog(@"MyApp - Unresolved error %@, %@", error, [error userInfo]);
exit(-1); // Fail
}
太字の問題:
IF
プロジェクトを作成してからその親クライアントを削除すると、コードはステートメントの後に正しく続きます。「削除された」クライアントにアクセスしても、それはまだそこにあり、編集clientName
やその他のプロパティを使用して、すべて正常に保存できます。プロジェクトに移動してプロジェクトを開き、更新されたクライアントを確認できますclientName
。しかし、プロジェクトを介してクライアントにアクセスすると、アプリが終了します。
削除ルールが正しく設定されていませんか?[context save:&error]
エラーが発生した場合でも、呼び出すと削除が保存されますか?何かご意見は?
* edit-ブレークポイントエラーが停止する行:
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Client" inManagedObjectContext:passedManagedObjectContext];
スローされたエラー:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Client''
*** Call stack at first throw:
(
0 CoreFoundation 0x30897ed3 __exceptionPreprocess + 114
1 libobjc.A.dylib 0x3002f811 objc_exception_throw + 24
2 CoreData 0x3162f575 +[NSEntityDescription entityForName:inManagedObjectContext:] + 124
3 EasyMemo 0x00008ebb -[EditingViewController viewWillAppear:] + 1478
4 UIKit 0x31ec4d9b -[UINavigationController _startTransition:fromViewController:toViewController:] + 610
5 UIKit 0x31ec4ac3 -[UINavigationController _startDeferredTransitionIfNeeded] + 182
6 UIKit 0x31ebd21b -[UINavigationController pushViewController:transition:forceImmediate:] + 606
7 UIKit 0x31ebcfb3 -[UINavigationController pushViewController:animated:] + 34
8 EasyMemo 0x000058fd -[DetailProjectViewController tableView:didSelectRowAtIndexPath:] + 368
9 UIKit 0x31f7ae6f -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 662
10 UIKit 0x31f772af -[UITableView _userSelectRowAtIndexPath:] + 130
11 Foundation 0x349c7e8d __NSFireDelayedPerform + 368
12 CoreFoundation 0x3084e7fb __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 14
13 CoreFoundation 0x3084e2ad __CFRunLoopDoTimer + 860
14 CoreFoundation 0x3081f7a5 __CFRunLoopRun + 1088
15 CoreFoundation 0x3081f277 CFRunLoopRunSpecific + 230
16 CoreFoundation 0x3081f17f CFRunLoopRunInMode + 58
17 GraphicsServices 0x31e445f3 GSEventRunModal + 114
18 GraphicsServices 0x31e4469f GSEventRun + 62
19 UIKit 0x31e51123 -[UIApplication _run] + 402
20 UIKit 0x31e4f12f UIApplicationMain + 670
21 EasyMemo 0x0000259f main + 70
22 EasyMemo 0x00002554 start + 40
)
terminate called after throwing an instance of 'NSException'