'NSFetchedResultsController不支持更改跟踪和获取请求的NSDictionaryResultType' [英] 'NSFetchedResultsController does not support both change tracking and fetch request's with NSDictionaryResultType'

查看:237
本文介绍了'NSFetchedResultsController不支持更改跟踪和获取请求的NSDictionaryResultType'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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不支持更改跟踪和
fetch请求与NSDictionaryResultType'

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

提前感谢。

推荐答案

错误是指您试图获取 NSDictionary 结果,但是也期望获取结果控制器观察变化。因为更改只会通过 NSManagedObjects 传播,所以提取的结果控制器不能再执​​行其工作。

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.

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

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.

这篇关于'NSFetchedResultsController不支持更改跟踪和获取请求的NSDictionaryResultType'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆