Harry Harry - 9 months ago 49
iOS Question

Type 'String!' has no member 'photo'

I am following a tutorial on Youtube about CoreML: Real Time Camera object detection with machine learning - Swift 4 by Mr. Brian

captureSession.sessionPreset = .photo


In this line, the error says:


Type "String" has no member 'photo'.


dataOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "videoQueue"))


And another error is the 'self' part. The error is:


Cannot convert value of type 'ViewController' to expected argument type 'AVCaptureVideoDataOutputSampleBufferDelegate!'


Below is the whole code:

import UIKit
import AVFoundation
import AVKit
import Vision

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

// here is where we start up the camera
let captureSession = AVCaptureSession()
captureSession.sessionPreset = .photo

guard let captureDevice =
AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo) else { return }

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

captureSession.startRunning()

let previewLayer = AVCaptureVideoPreviewLayer(session:
captureSession)
view.layer.addSublayer(previewLayer!)
previewLayer!.frame = view.frame

let dataOutput = AVCaptureVideoDataOutput()
dataOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "videoQueue"))
captureSession.addOutput(dataOutput)

Joe Joe
Answer Source

I think you got the answer for second error, for first error replace the error line with below

SWIFT 3

captureSession.sessionPreset = AVCaptureSessionPresetPhoto

SWIFT 4

captureSession.sessionPreset = AVCaptureSession.Preset.photo
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download