Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CFString convert to String for kUTTypeImage in Swift 2.0 & XCODE 7

Tags:

ios

swift

swift2

I got an error convert CFString. Error message is:

Cannot assign a value of type '[CFString]' to a value of type '[String].

How to fix?

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)//
like image 354
GökhanT Avatar asked Sep 04 '15 22:09

GökhanT


1 Answers

From the header file:

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

So you can actually just delete that line.

But if you want to keep it, you just need to be explicit that you want a cast:

picker.mediaTypes = [kUTTypeImage as String]
like image 174
Aaron Brager Avatar answered Nov 10 '22 00:11

Aaron Brager