iOS 14 crash in NSFetchedResultsController's indexPathForObject function

Hi Team,

I've been facing a crash on iOS 14 onwards on using NSFetchedResultsController.

Precondition:

I'm using NSFetchRequest to initialise NSFetchedResultsController and in fetch request I'm using propertiesToFetch to fetch a single property, resultType as NSDictionaryResultType with returnsDistinctResults as YES for getting distinct results.

NSFetchedResultsController is used as a data source for a table in our application.

Problem:

This was working fine in <iOS 14 versions, but it's started to crash for iOS 14 and and above(14.1), the reason for the same is that the dictionary we pass to get the index path in function 'indexPathForObject' is failing to return the index path with exception unrecognised selector(logs attached).

I did not found any document or a new API which can be used for the same purpose.

Please let me know how we can resolve this issue.

Code Block
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
)
libcabi.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)



Thank You
Harish Pathak
Below are some code snippet from my code base for better understanding.

Fetch request for used for NSFetchedResultsController object:
Code Block
- (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;
}

Crashing code:

Code Block
- (NSIndexPath *)indexPathForObject:(id)object {
return [self.fetchedResultsController indexPathForObject:object];
}


Seems to be the same issue as https://developer.apple.com/forums/thread/7628

iOS 14 crash in NSFetchedResultsController's indexPathForObject function
 
 
Q