swift - Mapbox Snapshotter 和 Swift 并发
问题描述
我正在尝试将 Mapbox Snapshotter API 与新的 Swift 并发一起使用。这是使用的代码:
func snapshot(completion: @escaping (Result<Data, Error>) -> Void) {
// define snapshotter options
let snapshotter = MGLMapSnapshotter(options: options)
snapshotter.start { (image, error) in
if let error = error {
completion(.failure(error))
}
guard let snapshot = image else { return }
if let imageData = snapshot.image.jpegData(compressionQuality: 0.75) {
completion(.success(imageData))
}
}
}
func pathSnapshot() async -> Data {
do {
return try await withCheckedThrowingContinuation { continuation in
pathSnapshot() { result in
switch result {
case .failure(let error):
continuation.resume(throwing: error)
case .success(let data):
continuation.resume(returning: data)
}
}
}
} catch {
print("error")
return Data()
}
}
snapshot(completion: @escaping (Result<Data, Error>) -> Void) 的代码与经典的完成处理程序配合得很好。
不幸的是,使用 Swift 并发,这会导致崩溃并出现以下错误:线程 3:EXC_BAD_ACCESS (code=EXC_I386_GPFLT)。
有什么线索吗?
解决方案
推荐阅读
- javascript - Chrome 开发者工具无法检测清单
- c - 当我尝试打印 getenv() 输出时,为什么会出现分段错误?
- c - IRQ 表和地址
- angular - 如何使用 Angular 2 中的指令删除组件
- java - 如何检查元素何时在 Selenium 中将其状态从启用更改为禁用
- html - Only controls and audio load and work on video in chrome
- html - React use different value of input field than it is showing
- git - What are the programming languages used to develop a GitHub App or an OAuth App?
- regex - FreeBSD Bash - Unable to code a condition with regex
- c# - 将多个列表彼此相邻放置在控制台的列中