use*_*417 5 core-data crash-reports stack-trace swift ios11
请解释下面的崩溃..
#3。NSManagedObjectContext 0x1701c9ab0:xxxxxxxxx 0 libsystem_kernel.dylib 0x1848898e8 __ulock_wait + 8 1 libdispatch.dylib 0x18475977c _dispatch_ulock_wait + 48 2 libdispatch.dylib 0x1847598a4 _dispatch_thread_event_wait_slow + 36 3 libdispatch.dylib 0x1847574f0 _dispatch_barrier_sync_f_slow + 236 4 CoreData 0x187c0703c _perform + 232 5 CoreData 0x187c178b8 -[NSManagedObjectContext(_NestedContextSupport) )executeRequest:withContext:error:] + 176 6 CoreData 0x187b675e0 -[NSManagedObjectContextexecuteFetchRequest:error:] + 580 7 MyApp 0x1002f596c专门静态RecentItemsController.cleanupItems(inContext:ofType:limitingTo:sortingByAttribute:withPredicate :)(xxxxx.swift:182) 8 MyApp 0x1002f6574 静态 xxx.xxx(inStore:completion:) 中的专用闭包 #1 (xxx.swift:163) 9 MyApp 0x1002f5118 部分申请静态 xxx.xxx(inStore:completion:) 中的闭包 #1 (xxx.swift) 10 CoreData 0x187c0c214开发者提交块到NSManagedObjectContextPerform + 152 11 libdispatch.dylib 0x1847469a0 _dispatch_client_callout + 16 12 libdispatch.dylib 0x184754ad4 _dispatch_queue_serial_drain + 928 13 libdispatch.dylib 0x 18474a2cc _dispatch_queue_invoke + 884 14 libdispatch.dylib 0x184754fa8 _dispatch_queue_override_invoke + 344 15 libdispatch.dylib 0x184756a50 _dispatch_root_queue_drain + 540 16 libdispatch.dylib 0x1847567d0 _dispatch_worker_thread3 + 124 17 libsystem_pthread.dylib 0x18494f100 _pthread_wqthread + 1096 18 libsystem_pthread.dylib 0x18494ecac start_wqthread + 4
查看堆栈跟踪和cleanupItemsfunc 内部的代码,我相信问题出在强制展开代码中:
let itemsToDelete = try context.fetch(request) as! [R]
Run Code Online (Sandbox Code Playgroud)
首先要编写预防崩溃的代码如下
if let itemsToDelete = try context.fetch(request) as? [R] {
itemsToDelete.forEach(context.delete(_:))
log("Deleted \(itemsToDelete.count) \(type) item(s)")
}
Run Code Online (Sandbox Code Playgroud)
让我知道这是否有效。
| 归档时间: |
|
| 查看次数: |
2842 次 |
| 最近记录: |