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?
do {
let input = try AVCaptureDeviceInput(device: captureDevice) as AVCaptureDeviceInput
// moved the rest of the image capture into the do{} scope.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With