+import AVFoundation
 import Cocoa
 
 class ViewController: NSViewController {
 
-  var shouldRecord: Bool = false
+  let captureSession = AVCaptureSession()
+  let movieFileOutput = AVCaptureMovieFileOutput()
 
   @IBOutlet var textField: NSTextField!
   @IBOutlet var label: NSTextField!

    return false
  }
}

  }

  @IBAction func toggleRecording(_ sender: Any) {
    switch recordButton.state {
    case NSOnState:
      beginRecording()
    default:
      endRecording()
    }
  }

  func beginRecording() {
    DispatchQueue.global().async {
      self.captureSession.startRunning()
      let url = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("Desktop/recording.mov")
      self.movieFileOutput.startRecording(toOutputFileURL: url, recordingDelegate: self)
    }
  }

  func endRecording() {
    movieFileOutput.stopRecording()
  }
}

