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

  • SEARCH
  • Home
  • 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 6927065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:59:58+00:00 2026-05-27T10:59:58+00:00

I’m writing a test program that use a Tab Controller with multiple tab views.

  • 0

I’m writing a test program that use a Tab Controller with multiple tab views. The program downloads multiple XML files, parses and populates sqlite tables through Core Data. The Core Data variables and functions are in the App Delegate file following the Xcode created code.

I started by simply passing the managedObjectContext variable to each subview that needed it, as I initialized it in the App Delegate, e.g.:

FirstViewController *vc1;
vc1 = [[[FirstViewController alloc] initWithNibName:@"FirstView" bundle:nil] autorelease];
[vc1 setManagedObjectContext:self.managedObjectContext];

However, I have a function (resetData) that deletes the entire data store–deletes the persistent store files and sets all the Core Data variables (managedObjectContext, managedObjectModel, persistentStore, etc) to nil, reinitializing everything. This is so that the program can start from scratch and redownload all of the data from the network. When this happens, the subviews now point to the old managedObjectContext.

What’s the best way to update the managedObjectContext variable in all the subviews? Manually update the subviews’ managedObjectContext variables from the resetData function? Use NSNotificationCenter to send a notification to all views? Is completely deleting and reinitializing all the persistent store files overkill?

I currently have put this getter that just refers back to the App Delegate in all the classes that need to refer to the MOC:

- (NSManagedObjectContext *)managedObjectContext {
    MyAppDelegate* ad = (MyAppAppDelegate*)[[UIApplication sharedApplication] delegate];
    return [ad managedObjectContext];
}

I’m very new to Cocoa / iOS design patters am trying to figure out the most proper way to do these things! What I’ve got now works, but I wonder if there are unseen pitfalls or future problems? 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-05-27T10:59:59+00:00Added an answer on May 27, 2026 at 10:59 am

    IMHO passing the managedObjectContext into the ViewControllers is good practice. It makes testing easier and creates better reusable ViewControllers.

    One way to achieve the desired result would be to simply delete all objects from the store, while leaving the CoreData Stack intact. All view controllers would simply use the same context as before, but it does not contain objects anymore. But that might be to slow, depending on the number of objects.

    The fastest and most efficient way to delete all objects is indeed to remove the storage file. NSManagedObjectContext offers a setter for the persistent store coordinator. Have you tried to create a new storeCoordinator with a new file, set it as the storeCoordinator of your MOC and then release the old coordinator and delete the old file? You might need to send a Notification is this case, as all ViewControllers have to release their potentially retained managedObjects.

    Another idea, that just came to my mind, and that I have used before is to completely remove the complete viewController stack and then recreate it using the new managedObjectContext. You could easily download, parse and save the new data into it’s own separate managedObjectContext (featuring it’s own persistentStoreController and own store)in the background. Once that is finished, remove all controller from the window, keeping track of with controllers were shown. Then move the new store file overwriting the old one and recreate the viewController stack as it was before. While that sounds like an expensive operation, it is not. In my case the switch wasn’t even noticeable in the UI. The advantage over keeping the viewControllers is, that it is by far less likely, that old managedObjects are still lurking around somewhere, thus leading to less code requiring additional editing. If your viewControllers are already set up the way apple recommends chances are good that this switch will “just work”.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.