Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImagePickerController and fatal error: array element cannot be bridged to Objective-C

I am creating UIImagePickerController to take a photo like this. However, at this statement,

    cameraUI.mediaTypes  = [kUTTypeImage]

it shows error like this:

fatal error: array element cannot be bridged to Objective-C

How shall I do? I am now using Xcode 6 beta version 4.

func presentCamera()
{
    cameraUI = UIImagePickerController()
    cameraUI.delegate = self
    cameraUI.sourceType = UIImagePickerControllerSourceType.Camera
    cameraUI.mediaTypes  = [kUTTypeImage]
    cameraUI.allowsEditing = false
    self.presentViewController(cameraUI, animated: true, completion: nil)
}

Edited - I have got error like this. enter image description here

like image 515
Khant Thu Linn Avatar asked Jul 27 '14 13:07

Khant Thu Linn


1 Answers

You need to import MobileCoreServices as kUTTypeImage defined in MobileCoreServices as let kUTTypeImage: CFString!.

So add the framework MobileCoreServices and write import MobileCoreServices in your .swift file.

Go to BuildPhase -> Link Libraries -> + -> MobileCoreServices.framework

and add import MobileCoreServices in your .swift file.

Edit: Replace your line with as kUTTypeImage is optional so unwrap it

cameraUI.mediaTypes  = [kUTTypeImage!]
like image 150
codester Avatar answered Oct 30 '22 06:10

codester