UIImagePickerController和致命错误:数组元素无法桥接到Objective-C

时间:2014-07-27 13:56:54

标签: ios objective-c arrays swift uiimagepickercontroller

我正在创建UIImagePickerController来拍摄这样的照片。但是,在本声明中,

    cameraUI.mediaTypes  = [kUTTypeImage]

它显示如下错误:

  

致命错误:数组元素无法桥接到Objective-C

我该怎么办?我现在正在使用Xcode 6 beta版本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)
}

已编辑 - 我有这样的错误。 enter image description here

1 个答案:

答案 0 :(得分:11)

您需要将MobileCoreServices定义为kUTTypeImage MobileCoreServices中定义的let kUTTypeImage: CFString!

所以添加框架MobileCoreServices并在import MobileCoreServices文件中写下.swift

转到BuildPhase - > Link Libraries - > + - > MobileCoreServices.framework

并在import MobileCoreServices文件中添加.swift

编辑:替换你的行,因为kUTTypeImage是可选的,所以打开它

cameraUI.mediaTypes  = [kUTTypeImage!]