NSFetchedResultsController中的iOS 14崩溃';s indexPathForObject函数
我在iOS 14上使用NSFetchedResultsController时一直面临崩溃 前提条件: 我使用NSFetchRequest初始化NSFetchedResultsController,在FetchRequest中,我使用propertiesToFetch获取单个属性,resultType为NSDictionaryResultType,returnsDistinctResults为YES,以获得不同的结果。下面是用于NSFetchedResultsController对象的获取请求NSFetchedResultsController中的iOS 14崩溃';s indexPathForObject函数,ios,objective-c,swift,nsfetchedresultscontroller,ios14,Ios,Objective C,Swift,Nsfetchedresultscontroller,Ios14,我在iOS 14上使用NSFetchedResultsController时一直面临崩溃 前提条件: 我使用NSFetchRequest初始化NSFetchedResultsController,在FetchRequest中,我使用propertiesToFetch获取单个属性,resultType为NSDictionaryResultType,returnsDistinctResults为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)
谢谢你如果你能分享相关的代码,那会有帮助。@RobertCrabtree虽然问题很简单,但为了更好地理解,我添加了一些代码,这与在iOS vesrions<14.0中工作的代码是一样的,苹果API在14.0及以上版本中被破坏了。我面临着完全相同的问题:在iOS 13.7及以下版本中工作,不在iOS 14+中。只需一个简单的
indepath(forObject:)
调用。我没有在通知中进行调用,它正在主线程中运行,我无法理解。。。