title: Working with the same NSManagedObjectContext in multiple tabs
body: <p>I have a tab bar controller with different view controllers all using the same managed object context, being set up as follows:</p>
  
  <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
  
  RootViewController *rootVC = [[RootViewController alloc] initWithStyle:UITableViewStyleGrouped];
  rootViewController.managedObjectContext = self.managedObjectContext;
  UINavigationController *rootNavCon = [[UINavigationController alloc] initWithRootViewController:rootVC];
  [rootVC release];
  
  SettingsTableViewController *settingsVC = [[SettingsTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
  settingsVC.managedObjectContext = self.managedObjectContext;
  UINavigationController *settingsNavCon = [[UINavigationController alloc] initWithRootViewController:settingsVC];
  [settingsVC release];
  
  tabBarController = [[UITabBarController alloc] init];
  NSArray *controllers = [NSArray arrayWithObjects:rootNavCon, settingsNavCon, nil];
  tabBarController.viewControllers = controllers;
  
  [self.window addSubview:tabBarController.view];
  [self.window makeKeyAndVisible];
  
  return YES;
  </code></pre>
  
  <p>}</p>
  
  <p>The idea is similar to the Recipes sample code if there were another tab called Settings which offered an option to managed the Category objects.  The problem is that if you navigate to the view where the user can select the Category, but then go to the settings tab and delete, add, or edit a Category, when returning to the Recipes tab the changes will not be immediately reflected.  Thus selecting a deleted Category would raise an exception.</p>
  
  <p>What is the best way to deal with this?  I was thinking about setting up an NSNotification to alert the views whenever an important change had occurred, but wasn't sure if there is a better way to do this, such as querying [managedObjectContext hasChanges] when a view appears. (Although that wouldn't seem to work if the context had already been saved.)</p>