gpt4 book ai didi

iphone - 如何修复 ‘NSObjectInaccessibleException’ 获取请求在被 NSManagedObjectContext 使用之前无法响应 -entity'

转载 作者:行者123 更新时间:2023-11-28 18:24:25 25 4
gpt4 key购买 nike

代码在 iOS5+ 中运行良好:

NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"FooBar"];
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"ident"
ascending:NO
selector:@selector(compare:)]];
request.predicate = [NSPredicate predicateWithFormat:@"xxx = %@", @"yyy"];

self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:model.managedObjectContext
sectionNameKeyPath:nil
cacheName:nil];

但在 iOS 4 中,出现以下错误:

'NSObjectInaccessibleException', reason: 'This fetch request (0x70d4700) 
was created with a string name (FooBar), and cannot respond to -entity
until used by an NSManagedObjectContext'

2012-11-08 12:12:18.093 hello[1566:11d03] *** Terminating app due to uncaught
exception 'NSObjectInaccessibleException', reason: 'This fetch request
(0x70d4700) was created with a string name (FooBar), and cannot respond
to -entity until used by an NSManagedObjectContext'
*** Call stack at first throw:
(
0 CoreFoundation 0x012405a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0104a313 objc_exception_throw + 44
2 CoreData 0x000be68f -[NSFetchRequest entity] + 159
3 CoreData 0x0019f7fb -[NSFetchedResultsController initWithFetchRequest:managedObjectContext:sectionNameKeyPath:cacheName:] + 763
...

我该如何解决这个错误?

最佳答案

fetchRequestWithEntityName: 仅适用于 iOS 5 及更高版本。

在 iOS 4 上,你必须先创建一个 NSEntityDescription:

NSEntityDescription *fooBarEntity = [NSEntityDescription entityForName:@"FooBar" inManagedObjectContext:model.managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:fooBarEntity];

关于iphone - 如何修复 ‘NSObjectInaccessibleException’ 获取请求在被 NSManagedObjectContext 使用之前无法响应 -entity',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13284673/

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