2015-09-04 38 views
6

我得到了一個錯誤轉換CFString。錯誤消息是:在Swift 2.0和XCODE 7中將CFString轉換爲字符串kUTTypeImage

無法將類型'[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)// 

回答

10

從頭文件:

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

因此可以真正地刪除該行。

但是,如果你想保留它,你只需要明確你想要鑄造:

picker.mediaTypes = [kUTTypeImage as String] 
+0

謝謝您的回答 –

相關問題