ios - 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 方法中。谁能让我知道导致崩溃的原因以及我能做些什么来防止它?谢谢。
解决方案
通常 sigtrap 用于意外 nil ,因此您可以保护这部分:
message.messageId!
推荐阅读
- sql - 根据申请日期选择状态
- sql - Oracle - 列出我在架构中拥有的权限 - 命令
- linux-kernel - 如何获取 V4L2 DMA 虚拟地址的物理地址?
- angularjs - 将 ngModel 指令添加到 Javascript 中的动态元素
- python - 尝试在 PYQT5 中查看 EXR 文件时 Python 崩溃
- react-native - 如何通过道具更改状态变量?
- algorithm - implement random 0 1 with custom parameter
- scala - 如何执行反射以查找扩展 Scala 中基类的所有类?
- python - 在对象字典中查找最小值
- r - 如何重复代码更改R中序列中的变量