[英]Swift 2.0 Type '()' does not conform to protocol
I'm implementing this method while using the camera in a view controller
我在
view controller
使用相机时正在实现此方法
let captureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
//... code
if let device = captureDevice {
do {
if (try device.lockForConfiguration()) {
device.focusPointOfInterest = focusPoint
device.focusMode = AVCaptureFocusMode.ContinuousAutoFocus
device.exposurePointOfInterest = focusPoint
device.exposureMode = AVCaptureExposureMode.ContinuousAutoExposure
device.unlockForConfiguration()
}
}
catch {
print("Error")
}
}
//... code
Trying to convert to Swift 2.0
I found this error Type '()' does not conform to protocol to 'BooleanType'
at line 尝试转换为
Swift 2.0
我发现此错误Type '()' does not conform to protocol to 'BooleanType'
行上的Type '()' does not conform to protocol to 'BooleanType'
if (try device.lockForConfiguration())
Actually I'm trying to figure out how to solve this, how can I make this a 'BooleanType'
? 实际上,我试图弄清楚如何解决此问题,如何使它成为
'BooleanType'
? In Swift 1.2
my code was simply 在
Swift 1.2
我的代码很简单
if (device.lockForConfiguration())
Thanks in advance. 提前致谢。
It looks that lockForConfiguration returns Void and throws, so return value does not conform to BooleanType. 看起来lockForConfiguration返回了Void并抛出,因此返回值不符合BooleanType。
I think that the following code should work for you: 我认为以下代码应为您工作:
if let device = captureDevice {
do {
try device.lockForConfiguration()
device.focusPointOfInterest = focusPoint
device.focusMode = AVCaptureFocusMode.ContinuousAutoFocus
device.exposurePointOfInterest = focusPoint
device.exposureMode = AVCaptureExposureMode.ContinuousAutoExposure
device.unlockForConfiguration()
}
catch {
print("Error")
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.