Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8110113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:38:30+00:00 2026-06-06T01:38:30+00:00

I was looking at the Pro Core Data examples and I was wondering what

  • 0

I was looking at the Pro Core Data examples and I was wondering what a good way to pass around the ManagedObjectContext is. In the examples in the book, I see the author initialize the ManagedObjectContext in the AppDelegate, then he does this in MasterViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    self.title = NSLocalizedString(@"League Manager", @"League Manager");
    id delegate = [[UIApplication sharedApplication] delegate];
    self.managedObjectContext = [delegate managedObjectContext];
    }
    return self;
}

Then when a new ViewController is pushed on the stack from a table row selection, this is done:

NSManagedObject *team = [[self fetchedResultsController] objectAtIndexPath:indexPath];
  TeamViewController *teamViewController = [[TeamViewController alloc] initWithMasterController:self team:team];
  [self presentModalViewController:teamViewController animated:YES];

Using StoryBoards, I don’t see that type of init method anymore. I see the prepareForSegue is mainly used and I see in the Beginning iOS 5 Development book, the author would do something like this:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        UIViewController *destination = ((UINavigationController *)segue.destinationViewController).topViewController;

        if ([destination  respondsToSelector:@selector(setDelegate:)]) {
            [destination setValue:self forKey:@"delegate"];
        }

I can’t figure out a good way to keep my classes decoupled and have a reference to the managedObjectContext in my viewControllers. Do I have a managedObjectContext that I just set on all my view controllers that need to see it? Do I do what the author in the first example did and keep a reference to the MasterViewController that has the reference and pass that around to my different ViewControllers? I’m not sure what is “best practices” for something like this. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T01:38:31+00:00Added an answer on June 6, 2026 at 1:38 am

    prepareForSegue:sender: is indeed the preferred way to pass data from one view controller to another when using storyboards. The example prepareForSegue code you posted is exactly how you’d do it. I have exactly this code in one of my apps:

    - (void) prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender
    {
        if( [[segue identifier] isEqualToString:@"showLog"] ) {
            UIViewController* logView = segue.destinationViewController;
            if( [logView respondsToSelector:@selector(setManagedObjectContext:)] ) {
                [logView setValue:self.managedObjectContext forKey:@"managedObjectContext"];
            }
        }
    }
    

    The Storyboard session from last year’s WWDC is good watching, if you haven’t seen it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for a newer version of the Pro*C/C++ to upgrade my procui.exe
Looking for a good set of base objects to start a website up in
Looking to move data from a table A to history table B every X
Looking at adding some data graphing to a new iPhone app in development (ala
Looking for advice/pro's/con's on using the memory cache servers for pub/sub esp wrt a
I'm looking at buying a MacBook Pro to replace my tiring laptop. My day
I'm looking to upgrade from Visual Studio 2008 Pro to Visual Studio 2010 Pro
I'm looking for a good ORM for an upcoming project. The database will have
I'm looking at new architecture for my site and was wondering if pairing NHibernate
We are looking to replace our usage of Authorize.net. I've spent a good deal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.