Hi I am trying to set my UIViewController's
managed object context, but the object context is not saved. Here's the code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
my_TableViewController *viewController = [mainStoryboard instantiateViewControllerWithIdentifier:@"coretut"];
if ([viewController isKindOfClass:[my_TableViewController class]]) {
[viewController setOManagedObjectContext:self.managedObjectContext];
}
NSLog(@"%@", self.managedObjectContext);
NSLog(@"%@", viewController.oManagedObjectContext);
}
The output for the following is
Apple_Tutorial[11241:461826] <NSManagedObjectContext: 0x7fb558d86600>
Apple_Tutorial[11241:461826] <NSManagedObjectContext: 0x7fb558d86600>
However when i call
NSLog(@"%@", self.oManagedObjectContext);
In viewDidLoad
() for my_TableViewController
the output is null
. oManagedObjectContext is declared as (strong, nonatomic)
. Does anyone know why oManagedObjectContext went to null?
viewDidLoad code:
- (void)viewDidLoad {
[super viewDidLoad];
UINib *nib = [UINib nibWithNibName:@"my_TableViewCell" bundle:nil];
[[self tableView] registerNib:nib forCellReuseIdentifier:@"tableViewCell"];
NSLog(@"%@", self.oManagedObjectContext);
}