Error: Type 'String!' has no member 'video'

Viewed 2850
import UIKit
import AVKit

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

//start camera

        let captureSession = AVCaptureSession()

        guard let captureDevice =
           AVCaptureDevice.default(for: .video) else { return }
        guard let input = try? AVCaptureDeviceInput(device:
                captureDevice ) else { return }
        captureSession.addInput(input)

        captureSession.startRunning()
    }
}

I get the error in this line at (for: .video):

AVCaptureDevice.default(for: .video) else { return }
5 Answers

I got this exact error when building with "Swift language Version" set to "Swift 3.3".

Changing the swift language version from "3.3" to "4.1" solved the issue for me.

I'm just trying to convert my project to Swift4. This works for me.

device = AVCaptureDevice.default(for: AVMediaType.video)
Related