title: How to create a button to change the camera view in Swift?
body: <p>I would like to know how I could change the camera view when I press a button. At the moment, I am using a boolean <code>var camera = false</code> and when I press a button, I want to change the value to true and get the other camera. But that is not working. 
  I now have this: </p>
  
  <pre><code> @IBAction func changeCamera(sender: AnyObject) {
  
      camera = true
  
  }
  
  override func viewWillAppear(animated: Bool) {
  
      captureSession = AVCaptureSession()
      captureSession!.sessionPreset = AVCaptureSessionPresetPhoto
      var captureDevice:AVCaptureDevice! = nil
      //var backCamera = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
      if (camera == false){
      let videoDevices = AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo)
  
  
      for device in videoDevices{
          let device = device as AVCaptureDevice
          if device.position == AVCaptureDevicePosition.Front {
              captureDevice = device
              break
          }
      }
      } else {
          var captureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
  
      }
  
      var error: NSError?
      var input = AVCaptureDeviceInput(device: captureDevice, error: &amp;error)
  
      if error == nil &amp;&amp; captureSession!.canAddInput(input) {
          captureSession!.addInput(input)
  
          stillImageOutput = AVCaptureStillImageOutput()
          stillImageOutput!.outputSettings = [AVVideoCodecKey: AVVideoCodecJPEG]
          if captureSession!.canAddOutput(stillImageOutput) {
              captureSession!.addOutput(stillImageOutput)
  
              previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
              previewLayer!.videoGravity = AVLayerVideoGravityResizeAspect
              previewLayer!.connection?.videoOrientation = AVCaptureVideoOrientation.Portrait
              previewView.layer.addSublayer(previewLayer)
  
              captureSession!.startRunning()
          }
      }
  
  }
  </code></pre>