Within an application it's possible to have different UIViewController
s that need to share the same NSManagedObject
. I'm usually do the following:
@interface CustomController : UIViewController
@property (nonatomic, retain) ProductNSManagedObject* productManaged;
@end
Then when I istantiate CustomController
I inject it like the following:
customController.productManaged = ....
once done, CustomController
is responsible to release it.
This approach works well (I don't know if is it correct), but what to do when a controller need that object but it's not a direct child of the controller that has that object? e.g.
MainController -> ChildController -> SubChildController -> ....
where MainController
has the managed object.
Do I have to create a lot of intermediary properties or do I need to execute a fresh NSFetchRequest
or something else?
The same aspect could be applied to the NSManagedObjectContext
. Searching around I've found that the context can be grabbed from the application delegate that posseses it (if any). But this approach lacks of flexibility as Marcus Zarra wrote in passing-around-a-nsmanagedobjectcontext-on-the-iphone.
Any suggestions? Thank you in advance.