私のアプリにはUITableViewController
、イベントリストを表示するものがあります。このコントローラーはManagedObjectContextSayを使用しParentContext
ます。これで、イベントが選択されている場合、ユーザーがイベントの詳細を編集できる詳細なViewControllerが表示されます。だから私は子コンテキストを作成しました、
ChildContext with type "NSPrivateQueueConcurrencyType"
ChildContext whose parent Context is "ParentContext".
私のコードは次のとおりです。
NSManagedObjectContext *childContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
childContext.parentContext = self.context ;
ここでも、別のドリルダウンが必要なフィールドと関係がいくつかあります。だから私は新しいViewControllerのために別のChildContextを作成しました、
GrandChildContext with type "NSPrivateQueueConcurrencyType"
GrandChildContext whose parent context is "ChildContext"
このプロセスは別のレベルに進みます(親(tableView)から子までの合計4レベル)
self.context - Parent Context
|
|
ChildContext
|
|
GrandChildContext
|
|
GrandGrandChildContext
私のエンティティは次のようになります
EntityA -- ( Edit View Controller - uses ChildContext )
|
|- Field1
|
|- Field2
|
|- RelationShip (1 to Many ) - ( Relationship Add / Edit View Controller - uses GrandChildContext )
|
|- Field1
| .
| .
|- Field3
|
|- Relationship ( 1 to Many ) - ( Relationship Add / Edit View Controller - uses GrandGrandChildContext )
|
|- Field1
|
|- Field2
これは、親子コンテキストを使用する正しい方法ですか?ある時点で私はのようになるからです1 NSMainQueueConcurrencyType MOC and 3 NSPrivateQueueConcurrencyType MOC
。
そうでない場合は?他に方法はありますか?
子コンテキストが多すぎると、アプリのパフォーマンスに影響しますか?
最初は、プロパティとNSArrayを使用してユーザーが入力したデータを管理し、ユーザーが[完了]ボタンを押すと、管理対象オブジェクトを更新/作成します。しかし、これは私のビューコントローラを汚す退屈な仕事です。そこで、更新を保存/破棄するのが非常に簡単な親子コンテキストに切り替えました。
ありがとう