gpt4 book ai didi

iphone - “NSFetchedResultsController 不支持更改跟踪和使用 NSDictionaryResultType 获取请求”

转载 作者:行者123 更新时间:2023-12-03 18:25:58 25 4
gpt4 key购买 nike

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

'NSFetchedResultsController does not support both change tracking and fetch request's with 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;
}

提前致谢。

最佳答案

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

使用 NSManagedObjectResultType 不起作用,因为 setPropertiesToFetch:不再适用。相反,在知道结果集后,您必须自己执行一些合并,这将使使用获取的结果 Controller 变得相当困难。

最好的答案是不要为获取的结果 Controller 设置缓存名称或委托(delegate),在这种情况下它将not perform any change tracking .

关于iphone - “NSFetchedResultsController 不支持更改跟踪和使用 NSDictionaryResultType 获取请求”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3245262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com