NSDictionaryResultType

NSDictionaryResultType

本文介绍了'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 不支持更改跟踪和使用 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 的更改跟踪和获取请求'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 17:31