     }
     
     // 2. setup outputs
-    let output = AVCapturePhotoOutput()
     if captureSession.canAddOutput(output) {
         captureSession.addOutput(output)
     }

import UIKit
import AVFoundation

class CameraController: UIViewController {
  
  lazy var dismissButton = UIButton(type: .system) <== {
    $0.setImage(#imageLiteral(resourceName: "right_arrow_shadow"), for: .normal)

    setupHUD()
  }
  
  func handleDismiss() {
    dismiss(animated: true, completion: nil)
  }
  
  // MARK: - Capture Photo
  
  func handleCapturePhoto() {
    print("Capturing photo...")
    
    let settings = AVCapturePhotoSettings()
    guard let previewFormatType = settings.availablePreviewPhotoPixelFormatTypes.first else { return }
    settings.previewPhotoFormat = [kCVPixelBufferPixelFormatTypeKey as String: previewFormatType]
    
    output.capturePhoto(with: settings, delegate: self)
  }
  
  func capture(_ captureOutput: AVCapturePhotoOutput, didFinishProcessingPhotoSampleBuffer photoSampleBuffer: CMSampleBuffer?, previewPhotoSampleBuffer: CMSampleBuffer?, resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Error?) {
    
    let imageData = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: photoSampleBuffer!, previewPhotoSampleBuffer: previewPhotoSampleBuffer!)
    
    let previewImage = UIImage(data: imageData!)
    
    let previewImageView = UIImageView(image: previewImage)
    view.addSubview(previewImageView)
    previewImageView.anchor(top: view.topAnchor, left: view.leftAnchor, bottom: view.bottomAnchor, right: view.rightAnchor, paddingTop: 0, paddingLeft: 0, paddingBottom: 0, paddingRight: 0, width: 0, height: 0)
    
    print("Finish processing photo sample buffer...")
  }
  
  // MARK: - setup
