In my app I have UITableViewController
that shows event list. This controller uses ManagedObjectContext Say ParentContext
. Now if any Event is selected, then a detailed View Controller is shown where users can edit the details of Event. So i have created a child context say,
ChildContext with type "NSPrivateQueueConcurrencyType"
ChildContext whose parent Context is "ParentContext".
My code is:
NSManagedObjectContext *childContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
childContext.parentContext = self.context ;
Now again there are some fields and relationships which needs another drill down. So i have created another ChildContext for the new view controller say,
GrandChildContext with type "NSPrivateQueueConcurrencyType"
GrandChildContext whose parent context is "ChildContext"
this process goes for another level ( Total 4 level from parent (tableView ) to child )
self.context - Parent Context
|
|
ChildContext
|
|
GrandChildContext
|
|
GrandGrandChildContext
My Entity Looks like this
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
Is this the right way of using Parent - Child context? Because at one point of time i will be having like 1 NSMainQueueConcurrencyType MOC and 3 NSPrivateQueueConcurrencyType MOC
.
If it is not? is there any other way?
Does too many child context affects apps's performance?
Initially i used Properties and NSArrays to manage user entered data and when user hits done button, i will update / create managed objects. But this is a tedious job it made my view controller dirty. So i switched to Parent-Child context which is very easy to save / discard updates.
Thanks