![](/img/trans.png)
[英]Type 'String' does not conform to protocol 'SequenceType' - Swift 2.0
[英]Swift 2.0 Type '()' does not conform to protocol
我在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
尝试转换为Swift 2.0
我发现此错误Type '()' does not conform to protocol to 'BooleanType'
行上的Type '()' does not conform to protocol to 'BooleanType'
if (try device.lockForConfiguration())
实际上,我试图弄清楚如何解决此问题,如何使它成为'BooleanType'
? 在Swift 1.2
我的代码很简单
if (device.lockForConfiguration())
提前致谢。
看起来lockForConfiguration返回了Void并抛出,因此返回值不符合BooleanType。
我认为以下代码应为您工作:
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.