开发者

'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 *aF开发者_运维技巧etchedResultsController = [[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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜