简体   繁体   English

Swift 2.0类型'()'不符合协议

[英]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.

相关问题 类型'String'不符合协议'SequenceType' - Swift 2.0 - Type 'String' does not conform to protocol 'SequenceType' - Swift 2.0 类型不符合协议Swift - Type does not conform to protocol Swift Swift - 类型“*”不符合协议“*” - Swift - Type '*' does not conform to protocol '*' 类型不符合协议序列类型 - Swift - type does not conform to protocol Sequence Type - Swift 类型“NSPersistentStore”在swift中不符合协议“BooleanType” - Type 'NSPersistentStore' does not conform to protocol 'BooleanType' in swift Swift:类型'ViewController'不符合协议'UIPageViewControllerDataSource' - Swift: Type 'ViewController' does not conform to protocol 'UIPageViewControllerDataSource' Swift:`类型'[String]'不符合协议'StringLiteralConvertible' - Swift: `Type '[String]' does not conform to protocol 'StringLiteralConvertible'` 类型“myViewController”不符合Swift中的协议UIPIckerDataSource - Type “myViewController” does not conform to protocol UIPIckerDataSource in Swift Swift - MultipeerConnectivity类型不符合协议 - Swift - MultipeerConnectivity Type does not conform to protocol Swift-类型'MenuViewController'不符合协议'GKGameCenterControllerDelegate' - Swift - Type 'MenuViewController' does not conform to protocol 'GKGameCenterControllerDelegate'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM