Record Video With Swift

Here's a simple example that illustrates how to record video with the Swift programming language on iOS.

First check to see if a camera source type is available:

if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {


            println("captureVideoPressed and camera available.")

            var imagePicker = UIImagePickerController()

            imagePicker.delegate = self
            imagePicker.sourceType = .Camera;
            imagePicker.mediaTypes = [kUTTypeMovie!]
            imagePicker.allowsEditing = false

            imagePicker.showsCameraControls = true


            self.presentViewController(imagePicker, animated: true, completion: nil)

        }

        else {
            println("Camera not available.")
        }

Then use this delegate method to actually save the video to the user's camera roll:

func imagePickerController(picker: UIImagePickerController!, didFinishPickingMediaWithInfo info:NSDictionary!) {

        let tempImage = info[UIImagePickerControllerMediaURL] as NSURL!
        let pathString = tempImage.relativePath
        self.dismissViewControllerAnimated(true, completion: {})

        UISaveVideoAtPathToSavedPhotosAlbum(pathString, self, nil, nil)

    }

Here's a complete project that I shared on Github.

I tested this on iOS7 and iOS8.