问题描述
在使用NSFetchedResultsController的iOS 14以后,我一直面临崩溃。
前提条件:
我正在使用NSFetchRequest初始化NSFetchedResultsController,并且在获取请求中,我正在使用propertiesToFetch来获取单个属性,resultType为NSDictionaryResultType,而returndistinctResults为YES,以获取不同的结果。以下是用于NSFetchedResultsController对象的获取请求。
- (NSFetchRequest *)fetchRequest {
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:NsstringFromClass([ABC class])];
request.predicate = [nspredicate predicateWithFormat:@"id = %@ AND removed = NO",[LMSAppDelegate sharedDelegate].module.cycleID];
request.returnsdistinctResults = YES;
request.propertiesToFetch = @[@"xyz"];
request.resultType = NSDictionaryResultType;
request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"xyz" ascending:YES]];
return request;
}
NSFetchedResultsController用作我们应用程序中表的数据源。
问题:
这在低于iOS 14版本的系统中仍能正常工作,但在iOS 14及更高版本(14.1)中已开始崩溃,其原因是我们传递的用于获取函数'indexPathForObject'中的索引路径的字典是未能返回异常识别器无法识别的索引路径(附加日志)。下面的功能崩溃了。
- (NSIndexPath *)indexPathForObject:(id)object {
return [self.fetchedResultsController indexPathForObject:object];
}
我没有找到可用于相同目的的任何文档或新API。
请让我知道如何解决此问题。
Stack Trace:
2020-10-27 11:50:22.165740+0530 XYZ[70020:1505717] -[__NSSingleEntryDictionaryI objectID]: unrecognized selector sent to instance 0x600007efeb80
2020-10-27 11:50:22.245891+0530 XYZ[70020:1505717] *** Terminating app due to uncaught exception 'NSinvalidargumentexception',reason: '-[__NSSingleEntryDictionaryI objectID]: unrecognized selector sent to instance 0x600007efeb80'
*** First throw call stack:
(
0 CoreFoundation 0x000000010b681126 __exceptionPreprocess + 242
1 libobjc.A.dylib 0x000000010b511f78 objc_exception_throw + 48
2 CoreFoundation 0x000000010b68fc6f +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
3 CoreFoundation 0x000000010b685666 ___forwarding___ + 1489
4 CoreFoundation 0x000000010b687698 _CF_forwarding_prep_0 + 120
5 CoreData 0x00000001051e3f23 -[_NSDefaultSectionInfo indexOfObject:] + 80
6 CoreData 0x000000010533671d -[NSFetchedResultsController indexPathForObject:] + 151
7 Lido_mPilot 0x0000000101ed4ac3 -[LMSFetchedResultsDataSource indexPathForObject:] + 99
8 Lido_mPilot 0x000000010238b1dc -[LMSFleetTableViewDataSource indexPathForObject:] + 140
9 Lido_mPilot 0x0000000101e160ad -[LMSFleetTableViewController viewWillAppear:] + 365
10 UIKitCore 0x0000000122115fb2 -[UIViewController _setViewAppearState:isAnimating:] + 654
11 UIKitCore 0x00000001221167db -[UIViewController __viewWillAppear:] + 106
12 UIKitCore 0x0000000122047534 -[UINavigationController _startTransition:fromViewController:toViewController:] + 726
13 UIKitCore 0x0000000122048371 -[UINavigationController _startDeferredTransitionIfNeeded:] + 851
14 UIKitCore 0x00000001220496dc -[UINavigationController __viewWillLayoutSubviews] + 150
15 UIKitCore 0x0000000122029f1e -[UILayoutContainerView layoutSubviews] + 217
16 UIKitCore 0x0000000122d9c9ce -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2874
17 QuartzCore 0x00000001099e9d87 -[CALayer layoutSublayers] + 258
18 QuartzCore 0x00000001099f0239 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 575
19 QuartzCore 0x00000001099fbf91 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 65
20 QuartzCore 0x000000010993c078 _ZN2CA7Context18commit_transactionEPNS_11TransactionEdPd + 496
21 QuartzCore 0x0000000109972e13 _ZN2CA11Transaction6commitEv + 783
22 UIKitCore 0x00000001228701a3 _afterCACommitHandler + 164
23 CoreFoundation 0x000000010b5ee6b3 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
24 CoreFoundation 0x000000010b5e8f3f __CFRunLoopDoObservers + 547
25 CoreFoundation 0x000000010b5e94e2 __CFRunLoopRun + 1113
26 CoreFoundation 0x000000010b5e8b9e CFRunLoopRunSpecific + 567
27 GraphicsServices 0x000000010e2e3db3 GSEventRunModal + 139
28 UIKitCore 0x000000012283faf3 -[UIApplication _run] + 912
29 UIKitCore 0x0000000122844a04 UIApplicationMain + 101
30 Lido_mPilot 0x0000000102421ce1 main + 193
31 libdyld.dylib 0x000000010cf64415 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSinvalidargumentexception',reason: '-[__NSSingleEntryDictionaryI objectID]: unrecognized selector sent to instance 0x600007efeb80'
terminating with uncaught exception of type NSException
CoreSimulator 732.17 - Device: iPad Pro (9.7-inch) (FE6E057B-B3C6-495D-9305-182325E6C237) - Runtime: iOS 14.0 (18A372) - DeviceType: iPad Pro (9.7-inch)
谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)