无法转换类型'(PHAsset)的值 - >虚空'预期参数类型'(([PHAsset]) - > Void)?'

时间:2017-08-16 00:36:42

标签: swift

我无法纠正此错误。

let vc = BSImagePickerViewController() self.bs_presentImagePickerController( vc , animated: true, select: {(asset: PHAsset) -> Void in },deselect: {(asset: PHAsset) -> Void in }, cancel: {(assets: PHAsset)-> Void in}, finish: { (assets: PHAsset) -> Void in for i in 0..

    func convertAssetsToImage() -> Void {
        if selectedAssests.count != 0 {
            for i in 0..<selectedAssests.count{
                let manager = PHImageManager.default()
                let option = PHImageRequestOptions()
                var thumbnail = UIImage()
                manager.requestImage(for: selectedAssests[i], targetSize: CGSize(width:200 , height : 200), contentMode: .aspectFill, options: option, resultHandler:{(result, info) -> Void in thumbnail = result!
                })

                let data = UIImageJPEGRepresentation(thumbnail, 0.7)
                let newImage = UIImage(data: data!)
                self.imageArray.append(newImage! as UIImage)
            }

            self.extImageOne.animationImages = self.imageArray
            self.extImageOne.animationDuration = 3.0
            self.extImageOne.startAnimating()
        }

    }
}

1 个答案:

答案 0 :(得分:0)

您已声明您的闭包采用PHAsset类型的单个对象,但您使用的API希望您的闭包采用PHAsset数组。重写你的闭包以取[PHAsset]而不是PHAsset,你应该解决你的问题。

编辑:

我用Google搜索BSImagePickerViewController类,找到了您尝试使用的API的签名。它看起来像:

func bs_presentImagePickerController(_ imagePicker: BSImagePickerViewController, animated: Bool, select: ((_ asset: PHAsset) -> Void)?, deselect: ((_ asset: PHAsset) -> Void)?, cancel: (([PHAsset]) -> Void)?, finish: (([PHAsset]) -> Void)?, completion: (() -> Void)?)

正如您所看到的,select:deselect:关闭只占用一个PHAsset,因此请将这两个关闭保留在上面的代码中。 cancel:finish:关闭都需要重写才能取代[PHAsset]