简体   繁体   中英

Cannot assign a value of type '[PHAsset]' to type 'UIImageView!'

Cannot assign value of '[PHAsset]' to type 'UIImageView!'

I'm having an issue here:

在此输入图像描述

UPDATED QUESTION

    // CONVERT PHASSET TO UIIMAGE
func getAsset(asset: PHAsset) -> UIImage {
    let manager = PHImageManager.defaultManager()
    let option = PHImageRequestOptions()
    var image = UIImage()
    option.synchronous = true
    manager.requestImageForAsset(asset, targetSize: CGSize(width: 100.0, height: 100.0), contentMode: .AspectFit, options: option, resultHandler: {(result, info)->Void in
        image = result!
    })
    return image
}




func doneButtonDidPress(images: [UIImage]) {



    self.imagePickerController.dismissViewControllerAnimated(true, completion: nil)
    var selectedImg = imagePickerController.stack.assets

    getAsset(selectedImg)
    self.SelectImageView.image = UIImage(named: chosenImg)



    }

But yet i get errors as shown in the image below

在此输入图像描述

The variable selectedImage is of type PHAsset

The variables self.backgroundImageView and self.SelectImageView are of type UIImageView

These two types do not match, so Swift will not allow you to make the assignments.

To make the assignment, you will have to convert PHAsset to UIImage and then assign this UIImage to the UIImageView

[PHAsset] is an array of PHAsset objects. To get an image from the array, get the PHAsset from the specific index you want and use requestImageForAsset:targetSize:contentMode:options:resultHandler: to get the image from the asset.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM