简体   繁体   English

无法将类型“[ArrayImages]”的值转换为预期的参数类型“[UIImage?]”

[英]Cannot convert value of type '[ArrayImages]' to expected argument type '[UIImage?]'

I pass an array of images to the function,我将一组图像传递给 function,

struct ArrayImages: Hashable {
    var asset: PHAsset
    var image: UIImage
}

@State var imagePost: [ArrayImages] = []

and then transfer to然后转移到

uploadImages(images: **imagePost**, itemId: save.id) { ( imageLinkArray) in *// <- mistake here

save.imagePost = imageLinkArray

the function itself is such function 本身就是这样

let storage = Storage.storage()

func uploadImages(images: [UIImage?], itemId: String, completion: @escaping (_ imagePost: [String]) -> Void) {

    var uploadedImagesCount = 0
      var imageLinkArray: [String] = []
      var nameSuffix = 0

      for image in images {
          let fileName = "ItemImages/" + itemId + "/" + "\(nameSuffix)" + ".jpg"
        let imageData = image!.jpegData(compressionQuality: 0.8)

          saveImageInFirebase(imageData: imageData!, fileName: fileName) { (imagePost) in

              if imagePost != nil {
                  imageLinkArray.append(imagePost!)
                 uploadedImagesCount += 1

                  if uploadedImagesCount == images.count {
                      completion(imageLinkArray)
                  }
              }
          }
          nameSuffix += 1
      }

} }

You need to extract an array of UIImage s from your imagePost , that's easily done using map :您需要从imagePost中提取UIImage的数组,这很容易使用map完成:

uploadImages(images: imagePost.map { $0.image }, itemId: save.id) { ( imageLinkArray) in 
    // ....
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将类型&#39;(NSDate)-&gt; NSTimeInterval的值转换为预期的参数类型&#39;Double&#39; - Cannot convert value of type '(NSDate) -> NSTimeInterval to expected argument type 'Double' 错误:无法将类型“ [String]”的值转换为预期的参数类型“ String?” - Error: Cannot convert value of type “[String]” to expected argument type “String?” swift:无法将类型“()”的值转换为预期的参数类型“ [Double]” - swift : Cannot convert value of type '()' to expected argument type '[Double]' 无法将类型“[String?]”的值转换为预期的参数类型“视频” - Cannot convert value of type '[String?]' to expected argument type 'Video' Swift错误:无法将“ArraySlice”类型的值转换为预期的参数类型 - Swift Error: Cannot convert value of type 'ArraySlice' to expected argument type 无法将“String”类型的值转换为预期的参数类型“[Any]” - Cannot convert value of type 'String' to expected argument type '[Any]' 无法将“Type”类型的值转换为预期的参数类型“(Type) throws -&gt; Bool” - Cannot convert value of type 'Type' to expected argument type '(Type) throws -> Bool' 无法将&#39;Option&#39;类型的值转换为预期的参数类型&#39;@noescape(Option)throws - &gt; Bool&#39; - Cannot convert value of type 'Option' to expected argument type '@noescape (Option) throws -> Bool' Swift:无法转换类型“(Any) throws -&gt; Bool”的值? 到预期的参数类型 &#39;(Any) throws -&gt; Bool? - Swift: Cannot convert value of type '(Any) throws -> Bool? to expected argument type '(Any) throws -> Bool? 无法将“[dataModel]”类型的值转换为预期的参数类型“(dataModel) throws -&gt; Bool” - Cannot convert value of type '[dataModel]' to expected argument type '(dataModel) throws -> Bool'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM