Swift 2 kUTTypeMovie?

I am trying to make a UIImagePickerController that only allows the user to take video. But when I try this:


vc.mediaTypes = [kUTTypeMovie!]


it doesn't work! I'm VERY new to swift so I'm probably just doing something wrong but I've been scowering the internet for answers and have found none. I would appriciate any help possible. Thanks!

Answered by OOPer in 20795022

Two things required:

First, import the module defining the constant.

import MobileCoreServices

And then, UTType constants are imported as CFString, and UIImagePickerViewController's mediaType claims [String], thus you need type casting.

    vc.mediaTypes = [kUTTypeMovie as String]


The description above are tested with Swift 2/Xcode 7 beta 2 (7A121l) with iOS9 SDK. Some details may change according to the SDK you use.

Accepted Answer

Two things required:

First, import the module defining the constant.

import MobileCoreServices

And then, UTType constants are imported as CFString, and UIImagePickerViewController's mediaType claims [String], thus you need type casting.

    vc.mediaTypes = [kUTTypeMovie as String]


The description above are tested with Swift 2/Xcode 7 beta 2 (7A121l) with iOS9 SDK. Some details may change according to the SDK you use.

iOS 14.0+

import UniformTypeIdentifiers

imagePickerController.mediaTypes = [UTType.movie.identifier]
Swift 2 kUTTypeMovie?
 
 
Q