let captureDeviceInput: AVCaptureDeviceInput?

    do {
        captureDeviceInput = try AVCaptureDeviceInput(device: device)
        if session.canAddInput(captureDeviceInput) {
            session.addInput(captureDeviceInput)
        }

    }

获取“可选类型'avCaptureDeviceImput'的值?”的编译错误未打开”。有办法解决这个问题吗?

最佳答案

有办法解决这个问题吗?
对。属性是可选类型。你得把它打开。

captureDeviceInput = try AVCaptureDeviceInput(device: device)
if let captureDeviceInput = captureDeviceInput
{
    if session.canAddInput(captureDeviceInput) {
            session.addInput(captureDeviceInput)
    }
}
else
{
    // Do something for a nil result (or nothing, if reasonable)
}

关于swift - Swift AVCaptureDevice中的可选类型,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47535139/

10-10 21:05