【问题标题】:Recieving this error message Swift 4.2: Instance member 'jpegData' cannot be used on type 'UIImage'; did you mean to use a value of this type instead? [duplicate]收到此错误消息 Swift 4.2:实例成员 'jpegData' 不能用于类型 'UIImage';你的意思是使用这种类型的值吗? [复制]
【发布时间】:2018-12-05 12:45:35
【问题描述】:
func uploadGoogleProfileImage(_ image:UIImage, completion: @escaping ((_ url:URL?)->())) {
    guard let uid = Auth.auth().currentUser?.uid else { return }
    let storageRef = Storage.storage().reference().child("userGoogleImage/\(uid)")

    guard let imageData = UIImage.jpegData(compressionQuality: 0.75) else { return }

    let metaData = StorageMetadata()
    metaData.contentType = "image/jpg"

    storageRef.putData(imageData, metadata: metaData) { metaData, error in
        if error == nil, metaData != nil {

            storageRef.downloadURL{ url, error in
                completion(url)
            }
        } else {
            // failed
            completion(nil)
        }
    }
}

错误显示在使用 UIImage.jpegData 的行上。不知道为什么我会收到此错误?

【问题讨论】:

  • 你想要... = image.jpegData...

标签: ios swift4.2


【解决方案1】:

jpegData 已更改为实例方法而不是类方法。如此变化

guard let imageData = UIImage.jpegData(compressionQuality: 0.75) else { return }

guard let data = image.jpegData(compressionQuality: 0.75) else { return }

会成功的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-29
    • 1970-01-01
    • 2021-09-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-24
    • 1970-01-01
    • 2017-04-23
    相关资源
    最近更新 更多