Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'NSFetchedResultsController does not support both change tracking and fetch request's with NSDictionaryResultType'

I have an application that was running just fine under OS3+. But it does not work under OS4. I get the following error message:

'NSFetchedResultsController does not support both change tracking and fetch request's with NSDictionaryResultType'

Does it ring a bell to anyone here?

- (NSFetchedResultsController *)fetchedResultsController {

    if (fetchedResultsController != nil) {
        return fetchedResultsController;
    }

    /*
     Set up the fetched results controller.
     */
    // Create the fetch request for the entity.
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    // Edit the entity name as appropriate.
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"myEntity" inManagedObjectContext:managedObjectContext];

    [fetchRequest setEntity:myEntity];

    [fetchRequest setResultType:NSDictionaryResultType];

    [fetchRequest setPropertiesToFetch :[NSArray arrayWithObjects:@"FIELD1",@"FIELD2",@"FIELD3",@"FIELD4",@"FIELD5",nil]];      

    // Setting unique values        
    [fetchRequest setReturnsDistinctResults:YES];       

    // Edit the sort key as appropriate.
    NSSortDescriptor *initialDescriptor = [[NSSortDescriptor alloc] initWithKey:@"FIELD1" ascending:YES];

    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:initialDescriptor, nil];

    [fetchRequest setSortDescriptors:sortDescriptors];      

    // Edit the section name key path and cache name if appropriate.
    // nil for section name key path means "no sections".       
    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"FIELD1" cacheName:@"myCache"];

    aFetchedResultsController.delegate = self;
    self.fetchedResultsController = aFetchedResultsController;
    [aFetchedResultsController release];
    [fetchRequest release];
    [initialDescriptor release];
    [sortDescriptors release];      

    return fetchedResultsController;
}    

Thanks in advance.

like image 793
Vincent Gaulet Avatar asked Jul 14 '10 10:07

Vincent Gaulet


1 Answers

The error is referring to the fact that you are trying to obtain NSDictionary results, but then also expecting the fetched results controller to watch for changes. Since changes will only propagate through NSManagedObjects, the fetched results controller can no longer perform its job.

Using NSManagedObjectResultType does not work because then setPropertiesToFetch: is no longer applicable. Instead, you would have to perform some coalescing of your own after the result set is known, which will make use with a fetched results controller rather difficult.

The best answer is to not set a cache name or a delegate for the fetched results controller, in which case it will not perform any change tracking.

like image 190
Justin Spahr-Summers Avatar answered Sep 20 '22 17:09

Justin Spahr-Summers