首页 > 解决方案 > 应用程序随机崩溃,NSInvalidArgumentException 无法识别的选择器发送到实例 0x800000000000000

问题描述

我的应用程序使用核心数据。我最近升级到 Xcode 10.2 和 swift 5,从那以后我收到与核心数据有关的随机崩溃。

从我收集到的信息来看,这是在尝试从后台线程更改核心数据时发生的(从服务器提取新数据后)。

我收到以下错误消息

2019-03-31 14:49:17.358685+0300 LeaderMES[24226:595701] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSTaggedDate objectForKey:]: unrecognized selector sent to instance 0x8000000000000000'

或者

2019-03-31 14:37:04.676485+0300 LeaderMES[23749:583097] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_NSCoreDataTaggedObjectID objectForKey:]: unrecognized selector sent to instance 0x8000000000000000'

不仅我的代码可以正常工作,而且这个实例编号看起来很可疑

我的应用程序连接到 crashlytics,它捕获了其中一个错误。这是它捕获的堆栈跟踪:

Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x1086f86e3 (Missing)
1  libobjc.A.dylib                0x10771bac5 objc_exception_throw
2  CoreFoundation                 0x108716ab4 (Missing)
3  CoreFoundation                 0x1086fd443 (Missing)
4  CoreFoundation                 0x1086ff238 (Missing)
5  libswiftCore.dylib             0x109914dcc (Missing)
6  libswiftCore.dylib             0x109b407b9 (Missing)
7  LeaderMES                      0x105080a8d closure #1 in LMNotificationRepository.loadNotificationHistory(forFactory:successCompletion:errorCompletion:) (LMNotificationRepository.swift:360)
8  LeaderMES                      0x105091271 partial apply for closure #1 in LMNotificationRepository.loadNotificationHistory(forFactory:successCompletion:errorCompletion:) (<compiler-generated>)
9  LeaderMES                      0x10510b872 closure #1 in LMHttpProvider.procedeRequest(_:completionHandler:) (LMHTTPProvider.swift:299)
10 LeaderMES                      0x10510e381 partial apply for closure #1 in LMHttpProvider.procedeRequest(_:completionHandler:) (<compiler-generated>)
11 LeaderMES                      0x1050ce176 thunk for @escaping @callee_guaranteed (@guaranteed Data?, @guaranteed NSURLResponse?, @guaranteed Error?) -> () (<compiler-generated>)
12 CFNetwork                      0x10adf6178 (Missing)
13 CFNetwork                      0x10ae0cc56 (Missing)
14 Foundation                     0x10666f412 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__
15 Foundation                     0x10666f31a -[NSBlockOperation main]
16 Foundation                     0x10666c1f4 -[__NSOperationInternal _start:]
17 Foundation                     0x106671f5b __NSOQSchedule_f
18 libdispatch.dylib              0x10a539ccf (Missing)
19 libdispatch.dylib              0x10a53ad02 (Missing)
20 libdispatch.dylib              0x10a53d6be (Missing)
21 libdispatch.dylib              0x10a53cd49 (Missing)
22 libdispatch.dylib              0x10a549ad3 (Missing)
23 libdispatch.dylib              0x10a54a330 (Missing)
24 libsystem_pthread.dylib        0x10a91c6b3 (Missing)
25 libsystem_pthread.dylib        0x10a91c3fd (Missing)

提到的所有缺失的dylib是什么?

我尝试使用 DispatchQueue 将所有核心数据活动移动到主线程,但没有成功。

我已经从模拟器中删除了该应用程序并重新安装它,到目前为止崩溃并没有重复。关于导致这次崩溃的任何想法?

标签: iosswiftswift5

解决方案


它看起来像是在 Xcode 10.2 中完成的非优化构建的错误。我没有在我的应用程序中使用核心数据,它也会崩溃

-[xxx objectForKey:]: unrecognized selector sent to instance 0x8000000000000000'

XXX 有时是__NSTaggedDate,有时是另一种类型,但地址始终是0x8000000000000000。当我通过有效键访问有效字典时,调试器会停在一行上,这根本没有帮助。当我将优化更改Optimise for speed -O为调试方案时,应用程序停止崩溃。


推荐阅读