'NSFetchedResultsController不支持使用NSDictionaryResultType更改跟踪和获取请求'

时间:2010-07-14 10:31:33

标签: iphone core-data ios4 nsfetchedresultscontroller

我有一个在OS3 +下正常运行的应用程序。但它在OS4下不起作用。我收到以下错误消息:

  

'NSFetchedResultsController不支持更改跟踪和   使用NSDictionaryResultType'

获取请求

这对这里的任何人都响了吗?

- (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;
}    

提前致谢。

1 个答案:

答案 0 :(得分:14)

错误指的是您尝试获取NSDictionary结果,但随后也期望获取的结果控制器监视更改。由于更改只会通过NSManagedObjects传播,因此获取的结果控制器无法再执行其工作。

使用NSManagedObjectResultType不起作用,因为setPropertiesToFetch:不再适用。相反,在结果集已知之后,您必须执行自己的某些合并,这将很难用于获取的结果控制器。

最佳答案是不为提取的结果控制器设置缓存名称或委托,在这种情况下它将not perform any change tracking