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 8433803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:29:16+00:00 2026-06-10T06:29:16+00:00

I have a brain class that I want to get Rest services and put

  • 0

I have a brain class that I want to get Rest services and put the info into core data.(I have looked at RestKit object mapping, but don’t fully understand it yet and want to keep it simpler). I want to have the Core Data knowledge in my engine class, but to cover my bases, I add the ManagedObjectContext to all the VC’s in the Tab Bar Controller, like so (in app delegate):

UITabBarController *tabBar = (UITabBarController *)self.window.rootViewController;

NSArray *viewControllers = [tabBar viewControllers];

NSManagedObjectContext *context = self.managedObjectContext;
self.engine.managedObjectContext = context;
for (id viewController in viewControllers) {
    [viewController setManagedObjectContext:context];
}

tabBar.selectedIndex = 2;

return YES;

However, I’m getting this error logged, when I try to check if coreData is available in my engine class:

        if (self.managedObjectContext == NULL || [self.managedObjectContext isEqual:[NSNull null]]) {
            NSLog(@"Error");
        }

What am I doing wrong? How does one pass Core data to a non-viewController Class correctly?

EDIT: right before the IF Statement, this in the debugger:

(lldb) po self.managedObjectContext
(NSManagedObjectContext *) $1 = 0x00000000 <nil>
(lldb) 
  • 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-10T06:29:18+00:00Added an answer on June 10, 2026 at 6:29 am

    Assuming that the ‘context’ property on all the other view controllers is strong, then the answer is that when you go to assign it, its not yet been created. Try this:

    NSManagedObjectContext *context = self.managedObjectContext;
    assert(context); // or NSLog context
    self.engine.managedObjectContext = context;
    

    Note that all users of context had better be on the same thread (I assume the main thread in our code).

    That said, a better solution would be for the class that manages the contect to “vend” dictionaries or arrays to interested parties, and keep all your context access located in one file (or class). This will make future debugger a big easier (IMHO)>

    EDIT: If the issue is that the value is set in the original code you posted – I assume this is your appDelegate, and the managedObjectContext is a strong property, then log the set operation:

    for (id viewController in viewControllers) {
        [viewController setManagedObjectContext:context];
        NSLog(@"Just set context=%@ in %@", viewController, [viewController managedObjectContext]);
    }
    

    Now, in each of your viewControllers, in viewDidLoad, add the line:

    NSLog(@"ViewController %@ context=%@", self, self.managedObjectContext);
    

    You will find one of these to be true:

    1) you set the moc on three viewControllers just fine, but somewhere else you set a viewController and didn’t set the moc (some other code)

    2) viewControllers is nil when you go to set the MOC on them (logic error)

    3) The ViewControllers you set the MOC on and the ones that log the message I suggested are the same, but the MOC is nil when the VC prints the log message. In this case something in the VC is resetting MOC to nil – maybe in viewDidLoad.

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

Sidebar

Related Questions

I have just had a brain block, I have a Deck object and want
Ok. I have looked EVERYWHERE and my little brain just can't understand a better
I have a AS spinner class that I downloaded from Jake Hawkes ( click
I have an object that contains, as part of its data, a linked list.
I want to do a search across 2 tables that have a many-to-one relationship,
Brain freeze here. What I want to do is have the Suckerfish drop down
Stack Overflowers: I have been racking my brain trying to get an List(of T)
I have a situation where I get a reference to an object that I
I have a observable collection of type Project, that I want to be displayed
I have an interface: interface IInterface { string Name { get; } } that

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.