首页 > 解决方案 > CollectionView cellForItemAt IndexPath 中的 SIGTRAP(TRAP_BRKPT) 崩溃

问题描述

我在我的生产应用程序中遇到了这个奇怪的崩溃。崩溃并不频繁,我无法重现它。

Crashed: com.apple.root.background-qos
0  AppName                    0x104a4c040 ViewController.(collectionView(UICollectionView, cellForItemAt : IndexPath) -> UICollectionViewCell).(closure #1) (ViewController.swift:1018)
1  AppName                    0x104a95270 _T0Ieg_IeyB_TR (Gif.swift)
2  libdispatch.dylib              0x1821cd088 _dispatch_call_block_and_release + 24
3  libdispatch.dylib              0x1821cd048 _dispatch_client_callout + 16
4  libdispatch.dylib              0x1821da378 _dispatch_root_queue_drain + 1028
5  libdispatch.dylib              0x1821d9f10 _dispatch_worker_thread3 + 120
6  libsystem_pthread.dylib        0x182473130 _pthread_wqthread + 1268
7  libsystem_pthread.dylib        0x182472c30 start_wqthread + 4

我正在使用后台队列更新collectionView 的cellForItemAt IndexPath 中的核心数据对象。我正在使用父子托管对象上下文来更新核心数据。

在第 1018 行,我有

DispatchQueue.global(qos: .background).async {
    DatabaseOperations.sharedInstance.incomingMessageRead(true, message.messageId!)
            }

它位于 cellForItem 方法中。谁能让我知道导致崩溃的原因以及我能做些什么来防止它?谢谢。

标签: iosswiftcore-data

解决方案


通常 sigtrap 用于意外 nil ,因此您可以保护这部分:

message.messageId!


推荐阅读