Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
445 views
in Technique[技术] by (71.8m points)

iphone - '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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...