I'm trying use UIImagePickerController
in swift but isn't work...
my ViewController:
class ViewController: UIViewController { @IBOutlet var imag : UIView = nil @IBAction func capture(sender : UIButton) { println("Button capture") if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) { var imag = UIImagePickerController() imag.delegate = self imag.sourceType = UIImagePickerControllerSourceType.Camera; imag.mediaTypes = kUTTypeImage imag.allowsEditing = false self.presentViewController(imag, animated: true, completion: nil) } } }
I have errors in following line of code
imag.delegate = self (Type'ViewControlles does confoorm to protocol 'UIImagePickerControllerDelegate') imagePicker.mediaTypes = kUTTypeImage (use of unresolved identifier kUTTypeImage)
I have read that kUTTypeImage
cant use in swift.but don't know, i am using bad this functions. Any help?
Thanks!!
kUTTypeImage is actually default for the mediaTypes property. It states, that one can only pick still images. If you are ok with this default, you don't need to set it explicitly in your code.
You should also import MobileCoreServices in the controller:
import MobileCoreServices
and then put the type inside square brackets like this:
image.mediaTypes = [kUTTypeImage]
Swift 2.0 and Higher
image.mediaTypes = [kUTTypeImage as String]
In Swift 2.0 (Xcode 7), you need to explicitly cast kUTTypeImage
(a CFString
) to String
:
picker.mediaTypes = [kUTTypeImage as String]
And you still need to import Mobile Core Services for this symbol to be defined:
import MobileCoreServices
That said, the default value of mediaTypes
is [kUTTypeImage]
anyway, so you don't need to set it if that's what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With