title: How to launch camera on viewDidLoad with UIImagePickerControllerDelegate?
body: <p>I have a new iOS app in Swift where I'm trying to show the camera as soon as the app is launched. In my view controller I have a single <code>UIView</code> object which I try to fill with the camera.</p>
  
  <p>The code in my view controller calls <code>UIImagePickerController</code> in the <code>viewDidLoad</code> method but nothing happens.</p>
  
  <p>Here is the code, any idea why nothing happens? Isn't the camera supposed to open on app launch with this code?</p>
  
  <pre><code>import UIKit
  
  class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
      let imagePicker = UIImagePickerController()
      @IBOutlet weak var imageViewer: UIImageView!
  
      override func viewDidLoad() {
          super.viewDidLoad()
          if UIImagePickerController.isCameraDeviceAvailable(   UIImagePickerControllerCameraDevice.Front) {
              imagePicker.delegate = self
              imagePicker.sourceType = UIImagePickerControllerSourceType.Camera
              presentViewController(imagePicker, animated: true, completion: nil)
          } else {
              println("no front camera available")
          }
  
          // Do any additional setup after loading the view, typically from a nib.
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
      func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
          dismissViewControllerAnimated(true, completion: nil)
          imageViewer.image = image
      }
  }
  </code></pre>
  
  <p><strong>UPDATE</strong>: if I add a button to the storyboard, connect it to the code and put the code from <code>viewDidLoad</code> in it, the camera works when the button is clicked:</p>
  
  <pre><code>@IBAction func presentImagePicker(sender: AnyObject) {
  
      if UIImagePickerController.isCameraDeviceAvailable( UIImagePickerControllerCameraDevice.Front) {
          imagePicker.delegate = self
          imagePicker.sourceType = UIImagePickerControllerSourceType.Camera
          presentViewController(imagePicker, animated: true, completion: nil)
      }
  }
  </code></pre>
  
  <p>I know that the camera works, but how to make it work without having to press a button?</p>