2015-06-20 62 views
11

我「升級」,從斯威夫特我的應用程序斯威夫特2和整個後續的錯誤來了: 'deviceInputWithDevice' is unavailable: use object construction 'AVCaptureDeviceInput(device:error:)'如何解決「deviceInputWithDevice不可用」的錯誤?

這裏是有問題的代碼:

let captureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo) 
    var input:AVCaptureDeviceInput 
    let error:NSError? 

    do { 
     let input = try AVCaptureDeviceInput.deviceInputWithDevice(captureDevice) as AVCaptureDeviceInput 
    } catch let error as NSError { 
     print(error) 
    } 

有人可以幫助我理解這個建議的解決方案:「使用對象結構」AVCaptureDeviceInput(device:error :)'「以及我可以如何實現它?

回答

18
do { 
     let input = try AVCaptureDeviceInput(device: captureDevice) as AVCaptureDeviceInput 
     // moved the rest of the image capture into the do{} scope. 
+1

你如何處理這個錯誤嗎? – daidai

+1

發現它'''catch讓錯誤成爲NSError {println(error)}''' – daidai