title: How to detect if front camera is active
body: <p>I have a uibutton to activate and inactivate flash.  I need to hide the button when I change camera to front as it doesn't have a flash in front . And, need to unhide when I change the cam to back again. Appreciate your help.</p>
  
  <pre><code> @IBAction func changeCamera(sender: AnyObject) {
  
      dispatch_async(self.sessionQueue, {
  
          let currentVideoDevice:AVCaptureDevice = self.videoDeviceInput!.device
          let currentPosition: AVCaptureDevicePosition = currentVideoDevice.position
          var preferredPosition: AVCaptureDevicePosition = AVCaptureDevicePosition.Unspecified
  
          switch currentPosition{
          case AVCaptureDevicePosition.Front:
              preferredPosition = AVCaptureDevicePosition.Back
  
          case AVCaptureDevicePosition.Back:
              preferredPosition = AVCaptureDevicePosition.Front
  
          case AVCaptureDevicePosition.Unspecified:
              preferredPosition = AVCaptureDevicePosition.Back
  
          }
  
  
          let device:AVCaptureDevice = takePhotoScreen.deviceWithMediaType(AVMediaTypeVideo, preferringPosition: preferredPosition)
  
          var videoDeviceInput: AVCaptureDeviceInput?
  
          do {
              videoDeviceInput = try AVCaptureDeviceInput(device: device)
          } catch _ as NSError {
              videoDeviceInput = nil
          } catch {
              fatalError()
          }
  
  
          self.session!.beginConfiguration()
  
          self.session!.removeInput(self.videoDeviceInput)
  
          if self.session!.canAddInput(videoDeviceInput){
  
              NSNotificationCenter.defaultCenter().removeObserver(self, name:AVCaptureDeviceSubjectAreaDidChangeNotification, object:currentVideoDevice)
  
              takePhotoScreen.setFlashMode(AVCaptureFlashMode.Auto, device: device)
  
              NSNotificationCenter.defaultCenter().addObserver(self, selector: "subjectAreaDidChange:", name: AVCaptureDeviceSubjectAreaDidChangeNotification, object: device)
  
              self.session!.addInput(videoDeviceInput)
              self.videoDeviceInput = videoDeviceInput
  
          }else{
              self.session!.addInput(self.videoDeviceInput)
          }
  
          self.session!.commitConfiguration()
  
  
  
          dispatch_async(dispatch_get_main_queue(), {
  
              self.snapButton.enabled = true
              self.cameraButton.enabled = true
  
          })
  
      })
  
  }
  
  
  @IBAction func toggleTorch(sender: AnyObject) {
      let device = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
      if (device.hasTorch) {
          do {
              try device.lockForConfiguration()
              if (device.torchMode == AVCaptureTorchMode.On) {
                  device.torchMode = AVCaptureTorchMode.Off
              } else {
                  do {
                      try device.setTorchModeOnWithLevel(1.0)
                  } catch {
                      print(error)
                  }
              }
              device.unlockForConfiguration()
          } catch {
              print(error)
          }
      }    }
  </code></pre>