Swift编译器错误:无法使用类型为'(() - >())'的参数列表调用'lockForConfiguration'

Mat*_*son 7 avfoundation ios avcapturesession swift

这是Swift 2.我似乎无法找到任何相关内容.我收到了错误

Cannot invoke 'lockForConfiguration' with an argument list of type '(() -> ())'
Run Code Online (Sandbox Code Playgroud)

在这里的第二行.

if let device = captureDevice {
            device.lockForConfiguration() {
                device.videoZoomFactor = 1.0 + CGFloat(ratioValue)
                device.unlockForConfiguration()
        }
        print(ratioValue)
    }
Run Code Online (Sandbox Code Playgroud)

hen*_*nes 11

在Swift 2中,该方法lockForConfiguration不接受任何参数,而是可以抛出一个NSError.你应该在把它包装do- try- catch发言.

do {
    try device.lockForConfiguration()
} catch {
    // handle error
    return
}

// When this point is reached, we can be sure that the locking succeeded
device.videoZoomFactor = 1.0 + CGFloat(ratioValue)
device.unlockForConfiguration()
Run Code Online (Sandbox Code Playgroud)