简体   繁体   中英

'-[Page compare:] unrecognized selector sent to instance' in CoreData

EDIT: Page is one of my entities

EIDT2: I'm always running with '-com.apple.CoreData.ConcurrencyDebug 1' and I've got no concurrency issues reported by that

I've stared to see a crash that I have no clue how to solve. I can't find when it was introduced it seems to come from CoreData. And also it's not 100% reproducible.

How can I track it down better? Is it me?

 Fatal Exception: NSInvalidArgumentException
-[Page compare:]: unrecognized selector sent to instance 0x281c640a0

With the following stack-trace:

Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x192cc896c __exceptionPreprocess
1  libobjc.A.dylib                0x1929e1028 objc_exception_throw
2  CoreFoundation                 0x192bc6dcc -[NSOrderedSet initWithSet:copyItems:]
3  CoreFoundation                 0x192ccd048 ___forwarding___
4  CoreFoundation                 0x192ccf3a0 _CF_forwarding_prep_0
5  Foundation                     0x1930afc3c _NSCompareObject
6  CoreData                       0x197670e24 +[NSFetchedResultsController(PrivateMethods) _insertIndexForObject:inArray:lowIdx:highIdx:sortDescriptors:]
7  CoreData                       0x197671034 -[NSFetchedResultsController(PrivateMethods) _updateFetchedObjectsWithInsertChange:]
8  CoreData                       0x19766b73c -[NSFetchedResultsController(PrivateMethods) _updateFetchedObjectsWithInsertedObjects:deletedObjects:updatedObjects:]
9  CoreData                       0x19779829c __82-[NSFetchedResultsController(PrivateMethods) _core_managedObjectContextDidChange:]_block_invoke
10 CoreData                       0x197757aac developerSubmittedBlockToNSManagedObjectContextPerform
11 CoreData                       0x1976221c4 -[NSManagedObjectContext performBlockAndWait:]
12 CoreData                       0x19762b81c -[NSFetchedResultsController(PrivateMethods) _core_managedObjectContextDidChange:]
13 Foundation                     0x19309306c __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_2
14 CoreFoundation                 0x192c2099c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__
15 CoreFoundation                 0x192c209ec ___CFXRegistrationPost1_block_invoke
16 CoreFoundation                 0x192c1fce4 _CFXRegistrationPost1
17 CoreFoundation                 0x192c1f97c ___CFXNotificationPost_block_invoke
18 CoreFoundation                 0x192b98910 -[_CFXNotificationRegistrar find:object:observer:enumerator:]
19 CoreFoundation                 0x192c1f2ac _CFXNotificationPost
20 Foundation                     0x192f81bfc -[NSNotificationCenter postNotificationName:object:userInfo:]
21 CoreData                       0x1976329dc -[NSManagedObjectContext(_NSInternalNotificationHandling) _postContextDidMergeChangesNotificationWithUserInfo:]
22 CoreData                       0x19762b6b4 -[NSManagedObjectContext(_NSInternalChangeProcessing) _createAndPostChangeNotification:deletions:updates:refreshes:deferrals:wasMerge:]
23 CoreData                       0x197635e00 -[NSManagedObjectContext(_NSInternalChangeProcessing) _postRefreshedObjectsNotificationAndClearList]
24 CoreData                       0x19762a4fc -[NSManagedObjectContext(_NSInternalChangeProcessing) _processRecentChanges:]
25 CoreData                       0x197631f1c -[NSManagedObjectContext _mergeChangesFromDidSaveDictionary:usingObjectIDs:]
26 CoreData                       0x19763228c -[NSManagedObjectContext mergeChangesFromContextDidSaveNotification:]
27 CoreData                       0x197757aac developerSubmittedBlockToNSManagedObjectContextPerform
28 libdispatch.dylib              0x19296dfd8 _dispatch_client_callout
29 libdispatch.dylib              0x192979cc8 _dispatch_main_queue_callback_4CF
30 CoreFoundation                 0x192c43cc8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
31 CoreFoundation                 0x192c3ea24 __CFRunLoopRun
32 CoreFoundation                 0x192c3df40 CFRunLoopRunSpecific
33 GraphicsServices               0x19cebb534 GSEventRunModal
34 UIKitCore                      0x196db6a60 UIApplicationMain
35 Calendarly                     0x1005812fc main + 29 (AppDelegate.swift:29)
36 libdyld.dylib                  0x192abce18 start

I think I've found it! As a last sorting-resort, I wanted to sort by primary-key and added this:

在此处输入图片说明

And it seems like that didn't work.. Because the crash happens when the names and years are the same, thus it's using: NSSortDescriptor(key: "self", ascending: true)

5 Foundation 0x1b8d8bc34 _NSCompareObject + 64 (NSSortDescriptor.m:275) in another crash I got from a the crash, which gave me the file as well (NSSortDescriptor.m), which got me thinking more...

Shortly after I posted the question I got another crash report which had the file-names in it as well (not just functions).

Which was:

5 Foundation 0x1b8d8bc34 _NSCompareObject + 64 (NSSortDescriptor.m:275

This lead me to believe it had something to do with NSSortDescriptor , and surely I added some sorting on self some time ago to keep a consistent order between items that had the same "name" and "year".

Interestingly the crash just occurred when inserting objects and not when loading up the collectionView.

I've actually found the post that led me to do this (though I must have missed the warning):

https://stackoverflow.com/a/52881564/897465

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM