代码之家  ›  专栏  ›  技术社区  ›  Anvil

无法转换“data?”类型的值。到预期的参数类型“uiimage”

  •  0
  • Anvil  · 技术社区  · 6 年前

    我正在尝试获取图像的数据,但我得到了以下错误:

    无法转换“data?”类型的值。到所需的参数类型“uiimage”

    代码:

    if let image = profileImageView.image {
        if let imageData = UIImagePNGRepresentation(image.pngData()) {
            PFUser.current()?["photo"] = PFFileObject(name: "profile.png", data: imageData)
        }
    }    
    

    我哪里做错了?

    1 回复  |  直到 6 年前
        1
  •  0
  •   Shehata Gamal    6 年前

    的初始值设定项 UIImagePNGRepresentation 采取了 UIImage 实例不 Data 实例,因此替换

    if let imageData = UIImagePNGRepresentation(image.pngData()) {
    

    具有

    if let imageData = UIImagePNGRepresentation(image) {
    

    或者最好用最新的 Way

    if let imageData = image.pngData() {   
    
    推荐文章