使用以下代码我收到此错误:
无法转换类型' in out NSError?' (又名' inout Optional')预期参数类型'()'
并且在这行代码中:
if device.lockForConfiguration(&error)
以下是代码的其余部分:
func focusWithMode(focusMode:AVCaptureFocusMode, exposureMode:AVCaptureExposureMode, point:CGPoint, monitorSubjectAreaChange:Bool){
dispatch_async(self.sessionQueue!, {
var device: AVCaptureDevice! = self.videoDeviceInput!.device
var error: NSError? = nil
if device.lockForConfiguration(&error){
if device.focusPointOfInterestSupported && device.isFocusModeSupported(focusMode){
device.focusMode = focusMode
device.focusPointOfInterest = point
}
if device.exposurePointOfInterestSupported && device.isExposureModeSupported(exposureMode){
device.exposurePointOfInterest = point
device.exposureMode = exposureMode
}
device.subjectAreaChangeMonitoringEnabled = monitorSubjectAreaChange
device.unlockForConfiguration()
}
})
}
答案 0 :(得分:1)
InSwift 2错误处理已从NSError
输入输出参数更改为try / catch(非例外)。
我认为这是从NSError
到try / catch:
func focusWithMode(focusMode:AVCaptureFocusMode, exposureMode:AVCaptureExposureMode, point:CGPoint, monitorSubjectAreaChange:Bool){
dispatch_async(self.sessionQueue!, {
var device: AVCaptureDevice! = self.videoDeviceInput!.device
var error: NSError? = nil
do {
try device.lockForConfiguration()
if device.focusPointOfInterestSupported && device.isFocusModeSupported(focusMode){
device.focusMode = focusMode
device.focusPointOfInterest = point
}
if device.exposurePointOfInterestSupported && device.isExposureModeSupported(exposureMode){
device.exposurePointOfInterest = point
device.exposureMode = exposureMode
}
device.subjectAreaChangeMonitoringEnabled = monitorSubjectAreaChange
device.unlockForConfiguration()
}
catch {
print("Locked error!")
}
})
}