拜托,我需要帮助解决问题,我将 Swift 3 的语法更改为 Swift 4,现在我在识别所有错误时遇到很多问题。最后一行中的函数 savePhoto 出现错误。, completionHandler: { _在
func takePhoto(_ previewLayer: AVCaptureVideoPreviewLayer, location: CLLocation?, completion: (() -> Void)? = nil) {
guard let connection = stillImageOutput?.connection(with: AVMediaType.video) else { return }
connection.videoOrientation = Helper.videoOrientation()
queue.async {
self.stillImageOutput?.captureStillImageAsynchronously(from: connection) {
buffer, error in
guard let buffer = buffer, error == nil && CMSampleBufferIsValid(buffer),
let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(buffer),
let image = UIImage(data: imageData)
else {
DispatchQueue.main.async {
completion?()
}
return
}
self.savePhoto(image, location: location, completion: completion)
}
}
}
func savePhoto(_ image: UIImage, location: CLLocation?, completion: (() -> Void)? = nil) {
PHPhotoLibrary.shared().performChanges({
let request = PHAssetChangeRequest.creationRequestForAsset(from: image)
request.creationDate = Date()
request.location = location
}, completionHandler: { _ in
DispatchQueue.main.async {
completion?()
}
})
}
最佳答案
重写为:
}, completionHandler: { (_, _) in
根据 documentation ,performChanges(_:completionHandler:)
中的完成处理程序接受两个参数,而不仅仅是一个。 _ in
,你用过的,只是一个单一参数的占位符。
关于ios - 无法将类型 '(_) -> ()' 的值转换为预期的参数类型 '((Bool, Error?) -> Void)?',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49365968/