title: saving a movie in swift
body: <p>I used the following code and did not succeed to save the movie
  Please tell me where am I wrong:</p>
  
  <p>On top I used, </p>
  
  <pre><code>import UIKit
  import MobileCoreServices
  import Foundation
  
  class RecordingViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate
  </code></pre>
  
  <p>The code itself is activated from a button,</p>
  
  <pre><code>//Recording a video
      @IBAction func recordANewVideoMessage(sender: UIButton) {
  
          //Initiate camera
          let picker = UIImagePickerController()
      picker.delegate = self
      if UIImagePickerController.isSourceTypeAvailable(.Camera)
      {
  
          picker.sourceType = .Camera
  
          if let availableTypes = UIImagePickerController.availableMediaTypesForSourceType(.Camera) {
  
  
              if (availableTypes as NSArray).containsObject(kUTTypeMovie) {
  
                  /* Set up the camera defaults, movie. no editing, 3 minutes max - consider presenting time during recording, medium quality */
                  picker.mediaTypes = [kUTTypeMovie]
                  picker.allowsEditing = false
                  picker.videoMaximumDuration = 180 // Perhaps reduce 180 to 120
                  picker.videoQuality = UIImagePickerControllerQualityType.TypeMedium
                  presentViewController(picker, animated: true, completion: nil) // presents the camera for the user
  
  
              }
          }
      }
  
  
  
  //In case the user cancels the movie
  func imagePickerControllerDidCancel(UIImagePickerController) {
  
          presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
      }
  
  
  func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
  
  
      let uniqueVideoName = "/temporaryVideoName" //will be altered when we have something unique for the user
  
      var video = info[UIImagePickerControllerReferenceURL] as! NSURL
  
      let urlVideo = video.URLByAppendingPathComponent("\(uniqueVideoName)"+".mpeg4").absoluteString
  
  
      if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(urlVideo))
          {
              UISaveVideoAtPathToSavedPhotosAlbum(urlVideo, nil, nil, nil)
          }
  
          presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
  
          }
  
  }
  </code></pre>