在Swift 2.0和XCODE 7中,如何将CFString转换为kUTTypeImage的String?

6

我遇到了一个CFString转换错误。错误信息如下:

无法将类型为 '[CFString]' 的值分配给类型为 '[String]' 的值。

如何修复?

picker.sourceType = UIImagePickerControllerSourceType.Camera
picker.allowsEditing = false
picker.mediaTypes = [kUTTypeImage] //Error Message : Cannot assign a value of type '[CFString]' to a value of type '[String]'
picker.delegate = self
picker.modalPresentationStyle = .Popover
presentViewController(picker, animated: true, completion: nil)//
1个回答

13

从头文件中:

public var mediaTypes: [String]
// default value is an array containing kUTTypeImage.

由于默认值就是您想要的,您实际上可以只删除那行代码。

但是如果您想保留它,您只需要显式地转换类型:

picker.mediaTypes = [kUTTypeImage as String]

感谢您的回答。 - GökhanT

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接