gpt4 book ai didi

ios - 错误: 'Call can throw but is not marked with try and error not handled'

转载 作者:行者123 更新时间:2023-12-03 09:10:00 28 4
gpt4 key购买 nike

我收到了上述错误,并尝试通过添加do/catch块来对此进行修改。由于某种原因,错误不会消失。有谁知道为什么会这样?

 override func viewDidAppear(animated: Bool) {
super.viewWillAppear(animated)

captureSession = AVCaptureSession()
captureSession?.sessionPreset = AVCaptureSessionPreset1920x1080

let backCamera = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)

do {

let input = AVCaptureDeviceInput(device: backCamera)

captureSession?.addInput(input)

stillImageOutput = AVCaptureStillImageOutput()
stillImageOutput?.outputSettings = [AVVideoCodecKey : AVVideoCodecJPEG]

if (captureSession?.canAddOutput(stillImageOutput) != nil){
captureSession?.addOutput(stillImageOutput)

previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer?.videoGravity = AVLayerVideoGravityResizeAspect
previewLayer?.connection.videoOrientation = AVCaptureVideoOrientation.Portrait
oview.layer.addSublayer(previewLayer!)
captureSession?.startRunning()

}

} catch {

}

}

最佳答案

提示在错误描述中:Error: 'Call can throw but is not marked with try and error not handled'
您尚未用try标记可能引发的 call

我没有在其中抛出的调用,而是找到了一个并在其前面放置try的调用。如果您要分配一个值,请尝试在=的右侧进行操作

编辑

只是看了看文档,看起来像是你的

let input = AVCaptureDeviceInput(device: backCamera)

可以抛出的声明。像这样在 =之后尝试一下
let input = try AVCaptureDeviceInput(device: backCamera)

然后,您可以在 print(error)中使用 catch来查看任何潜在错误

关于ios - 错误: 'Call can throw but is not marked with try and error not handled' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33711648/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com