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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:50:51+00:00 2026-06-07T18:50:51+00:00

I’m trying to select an object called selectedPractice of a Core Data entity called

  • 0

I’m trying to select an object called “selectedPractice” of a Core Data entity called “Practice” on a view controller called SelectorViewController, and then hold on to the results for use in another controller called RegularViewController. Both are UIViewControllers, as my existing app that I’m trying to append core data to doesn’t use Tab or NavigationControllers.

I’ve tried to set the ManagedObjectContexts of the two controllers to be the same as that of AppDelegate in AppDelegate.m using the following code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
SelectorViewController *svc;
    svc.managedObjectContext = self.managedObjectContext;
    svc.fetchedResultsController = self.fetchedResultsController;

    RegularViewController *rvc;
    rvc.managedObjectContext = self.managedObjectContext;
    rvc.fetchedResultsController = self.fetchedResultsController;
        return YES;
}

AppDelegate.m also has a setupFetchedResultsController method here (adapted from Tim Roadley’s excellent work):

- (void)setupFetchedResultsController
{
    // 1 - Decide what Entity you want
    NSString *entityName = @"Practice"; // Put your entity name here
    NSLog(@"AppDelegate Setting up a Fetched Results Controller for the Entity named %@", entityName);

    // 2 - Request that Entity
    NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:entityName];

    // 3 - Filter it if you want
    //request.predicate = [NSPredicate predicateWithFormat:@"Practice.name = Blah"];

    // 4 - Sort it if you want
    request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"name"
                                                                                     ascending:YES
                                                                                      selector:@selector(localizedCaseInsensitiveCompare:)]];

    // 5 - Fetch it
    self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
                                                                        managedObjectContext:self.managedObjectContext
                                                                          sectionNameKeyPath:nil
                                                                                   cacheName:nil];
    [self.fetchedResultsController performFetch:nil];
    NSLog(@"AppDelegate setupFetchedResultsController completed");
}

This runs fine with all the NSLogs displaying. There is then another instantiation of setupFetchedResultsController in SelectorViewController.m here, but it causes a crash with the following log. Is the issue that the FetchedResultsController is reinitiating ?

2012-07-12 20:49:07.652 WhiteHealth[6969:15b03] SelectorViewController
sorting entity complete 2012-07-12 20:49:07.653
WhiteHealth[6969:15b03] * Terminating app due to uncaught exception
‘NSInvalidArgumentException’, reason: ‘An instance of
NSFetchedResultsController requires a non-nil fetchRequest and
managedObjectContext’

- (void)performFetch
{
    if (self.fetchedResultsController) {
        if (self.fetchedResultsController.fetchRequest.predicate) {
            if (self.debug) NSLog(@"[%@ %@] fetching %@ with predicate: %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), self.fetchedResultsController.fetchRequest.entityName, self.fetchedResultsController.fetchRequest.predicate);
        } else {
            if (self.debug) NSLog(@"[%@ %@] fetching all %@ (i.e., no predicate)", NSStringFromClass([self class]), NSStringFromSelector(_cmd), self.fetchedResultsController.fetchRequest.entityName);
        }
        NSError *error;
        [self.fetchedResultsController performFetch:&error];
        if (error) NSLog(@"[%@ %@] %@ (%@)", NSStringFromClass([self class]), NSStringFromSelector(_cmd), [error localizedDescription], [error localizedFailureReason]);
    } else {
        if (self.debug) NSLog(@"[%@ %@] no NSFetchedResultsController (yet?)", NSStringFromClass([self class]), NSStringFromSelector(_cmd));
    }
    [pickerView reloadAllComponents];
}

- (void)setupFetchedResultsController
{
    // 1 - Decide what Entity you want
    NSString *entityName = @"Practice"; // Put your entity name here
    NSLog(@"SelectorViewController Setting up a Fetched Results Controller for the Entity named %@", entityName);

    // 2 - Request that Entity
    [NSFetchedResultsController deleteCacheWithName:nil]; 
    NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:entityName];
    NSLog(@"SelectorViewController requesting entity complete");

    // 3 - Filter it if you want
    //request.predicate = [NSPredicate predicateWithFormat:@"Person.name = Blah"];

    // 4 - Sort it if you want
    request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"name"
                                                                                     ascending:YES
                                                                                      selector:@selector(localizedCaseInsensitiveCompare:)]];
    NSLog(@"SelectorViewController sorting entity complete");

    // 5 - Fetch it
    self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
                                                                        managedObjectContext:self.managedObjectContext
                                                                          sectionNameKeyPath:nil
                                                                                   cacheName:nil];
    [self performFetch];

}
  • 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-07T18:50:54+00:00Added an answer on June 7, 2026 at 6:50 pm
    SelectorViewController *svc;
    svc.managedObjectContext = self.managedObjectContext;
    svc.fetchedResultsController = self.fetchedResultsController;
    
    RegularViewController *rvc;
    rvc.managedObjectContext = self.managedObjectContext;
    rvc.fetchedResultsController = self.fetchedResultsController;
        return YES;
    

    isn’t going to set the managedObjectContexts for you, you not initializing svc and rvc, all you’re doing is making objects. If you want to set the managedObject context, go into the viewDidLoad’s or just before you run the fetch request, and do this check:

    if (self.managedObjectContext == nil) {
        self.managedObjectContext = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
i got an object with contents of html markup in it, for example: string
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I want to construct a data frame in an Rcpp function, but when I

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.