Weird compile error with AVCapture after updating to Xcode 9 / Swift 4

Viewed 1232

I have a normal UIViewController that uses AVCapturePhoto in which I create a custom capture controller.

Everything worked properly until I update to Xcode 9 and converted my code to Swift 4 and now when I try to compile I get this compiling-error:

Undefined symbols for architecture x86_64: "__T0So22AVCapturePhotoSettingsC12AVFoundation01_abC16SwiftNativeTypesACWP", referenced from: __T05Union16CameraControllerC18handleCapturePhotoyyF in CameraController.o "__T012AVFoundation39_AVCapturePhotoSettingsSwiftNativeTypesPAAE016availablePreviewc11PixelFormatG0Says6UInt32VGfg", referenced from: __T05Union16CameraControllerC18handleCapturePhotoyyF in CameraController.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

And in the error tray this message is shown:

Apple Mach-O Linker Error Group

Any hint what may be causing this ?

Updated Info

Here's a Xcode 9 print screen of the error-log. Hope it helps on the compiling error solution.

enter image description here

Edit

Just performing some tests -- if I comment the class code, the compile-error goes away.

Is there anything wrong in the following class implementation that I'm missing in Swift 4 ??

import UIKit
import AVFoundation


class CameraController: UIViewController, AVCapturePhotoCaptureDelegate, UIViewControllerTransitioningDelegate {

    let dismissButton: UIButton = {
        let button = UIButton(type: .system)
        button.setImage(#imageLiteral(resourceName: "right_arrow_shadow").withRenderingMode(.alwaysOriginal), for: .normal)
        button.addTarget(self, action: #selector(handleDismiss), for: .touchUpInside)
        return button
    }()

    let capturePhotoButton: UIButton = {
        let button = UIButton(type: .system)
        button.setImage(#imageLiteral(resourceName: "capture_photo").withRenderingMode(.alwaysOriginal), for: .normal)
        button.addTarget(self, action: #selector(handleCapturePhoto), for: .touchUpInside)
        return button
    }()

    let output = AVCapturePhotoOutput()

    override func viewDidLoad() {
        super.viewDidLoad()

        transitioningDelegate = self
        setupCaptureSession()
        setupHUD()
    }


    // hiddes the status bar
    override var prefersStatusBarHidden: Bool { return true }

    //MARK: General funcs
    fileprivate func setupCaptureSession() {
        let captureSession = AVCaptureSession()

        //1. setup inputs - camera
        let captureDevice = AVCaptureDevice.default(for: AVMediaType.video)
        do {
            let input = try AVCaptureDeviceInput(device: captureDevice!)
            if captureSession.canAddInput(input) {
                captureSession.addInput(input)
            }
        } catch let err {
            print("Could not setup camera input:", err)
        }
        //2. setup outputs
        if captureSession.canAddOutput(output) {
            captureSession.addOutput(output)
        }
        //3.setup output preview
        let previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)      
        previewLayer.frame = view.frame
        view.layer.addSublayer(previewLayer)

        // starts the inputs/outputs
        captureSession.startRunning()
    }


    fileprivate func setupHUD() {
        // botão de captura
        view.addSubview(capturePhotoButton)
        capturePhotoButton.anchor(top: nil, left: nil, bottom: view.bottomAnchor, right: nil, paddingTop: 0, paddinfLeft: 0, paddingBottom: 24, paddingRight: 0, width: 80, height: 80)
        capturePhotoButton.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true

        // dismiss button
        view.addSubview(dismissButton)
        dismissButton.anchor(top: view.topAnchor, left: nil, bottom: nil, right: view.rightAnchor, paddingTop: 12, paddinfLeft: 0, paddingBottom: 0, paddingRight: 12, width: 50, height: 50)
    }


    @objc func handleCapturePhoto() {
        // processes the captured photo
        let settings = AVCapturePhotoSettings()
        guard let preview = settings.availablePreviewPhotoPixelFormatTypes.first else { return }
        settings.previewPhotoFormat = [kCVPixelBufferPixelFormatTypeKey as String: preview]
        output.capturePhoto(with: settings, delegate: self)
    }


    @objc func handleDismiss() {
        dismiss(animated: true, completion: nil)
    }


    // Camera delegate
    func photoOutput(_ captureOutput: AVCapturePhotoOutput, didFinishProcessingPhoto photoSampleBuffer: CMSampleBuffer?, previewPhoto previewPhotoSampleBuffer: CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Error?) {
        // access the captured image
        let imageData = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: photoSampleBuffer!, previewPhotoSampleBuffer: previewPhotoSampleBuffer!)
        let previewImage = UIImage(data: imageData!)

        // shows the image
        let containerView = PreviewPhotoContainerView()
        containerView.previewImageView.image = previewImage

        view.addSubview(containerView)
        containerView.anchor(top: view.topAnchor, left: view.leftAnchor, bottom: view.bottomAnchor, right: view.rightAnchor, paddingTop: 0, paddinfLeft: 0, paddingBottom: 0, paddingRight: 0, width: 0, height: 0)

    }   
}
1 Answers
Related