Use of undeclared type 'PHAsset' BSImagePicker
Asked Answered
P

1

9

I imported a module from CocoaPods inside swift. i did everythings as it needs to be done and it also works, because the module is succesfully imported. i now want to test some demo script of BSimagepicker but it says undeclared type : PHAsset.

What i need to do is to select different images and load this into some sort of imagepicker preview inside the app.

Someone can help to fix this error?

@IBOutlet var imageView: UIImageView!

@IBOutlet weak var PicLabel: UILabel!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    //startbsimpagepicker

    let vc = BSImagePickerViewController()

    bs_presentImagePickerController(vc, animated: true,
        select: { (asset: PHAsset) -> Void in
            // User selected an asset.
            // Do something with it, start upload perhaps?
        }, deselect: { (asset: PHAsset) -> Void in
            // User deselected an assets.
            // Do something, cancel upload?
        }, cancel: { (assets: PHAsset) -> Void in
            // User cancelled. And this where the assets currently selected.
        }, finish: { (assets: [PHAsset]) -> Void in
            // User finished with these assets
        }, completion: nil)

    //endbsimpagepicker
Premier answered 3/2, 2016 at 8:17 Comment(3)
You need to import Photos Framework via "import Photos" for PHAssetMown
That was the trick! Thanks very mutch. Only one more thing: import }, cancel: { (assets: PHAsset) -> Void in // User cancelled. And this where the assets currently selected. I get an error at the cancel. It says: cannot convert value of type (PPHAsset) Void to expected argument type PHAsset _. Void?Premier
About the line "cancel: { (assets: PHAsset) -> Void in" I think it should be "cancel: { (assets: [PHAsset]) -> Void in". You miss square brackets in your codes.Mown
P
36

[Since I was looking for an answer too and couldn't find it, I'll add this as an answer so in the future people will find it easier. Thanks to @Allen who provided the answer in the comments.]


You have to add the Photos Framework by writing:

import Photos

...at the beginning of your ViewController's source code.
That will allow you to use PHAsset.

Peppy answered 2/5, 2017 at 8:27 Comment(1)
This Was useful for me Thanks a lotReclamation

© 2022 - 2024 — McMap. All rights reserved.