jackreichert
jackreichert

Reputation: 1979

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

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?

Upvotes: 11

Views: 8379

Answers (1)

jackreichert
jackreichert

Reputation: 1979

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

Upvotes: 18

Related Questions