Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fix the error "deviceInputWithDevice is unavailable"?

Tags:

swift

swift2

I'm "upgrading" my app from Swift to Swift 2 and came across the follow error: 'deviceInputWithDevice' is unavailable: use object construction 'AVCaptureDeviceInput(device:error:)'

Here is the code in question:

    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)
    }

Can someone help me understand the suggested solution: "use object construction 'AVCaptureDeviceInput(device:error:)'" and how I can implement it please?

like image 532
jackreichert Avatar asked Jun 20 '15 00:06

jackreichert


Video Answer


1 Answers

    do {
        let input = try AVCaptureDeviceInput(device: captureDevice) as AVCaptureDeviceInput
        // moved the rest of the image capture into the do{} scope.
like image 81
jackreichert Avatar answered Oct 21 '22 12:10

jackreichert