Im trying to implement a profile picture complete with upload button to firebase. I'm using swift 4.0 and im stuck on the syntax which is required for converting the jpeg image into data.
an error message is displayed providing the fix to the new replacement code, and following the instructions another error is played.
@IBAction func uploadButtonWasTapped(_ sender: Any) {
progressView.isHidden = false
let randomID = UUID.init().uuidString
let uploadRef = Storage.storage().reference(withPath:
"images/(randomID).jpg")
guard let imageData =
imageView.image?.jpegData(compressionQuality:
0.75) else { return }
let uploadMetadata = StorageMetadata.init()
uploadMetadata.contentType = "image/jpeg"
let taskReference = uploadRef.putData(imageData, metadata:
uploadMetadata) { (downloadMetadata, error) in
if let error = error {
print("Oh no! Got and Error! \(error.localizedDescription)")
return
}
print("Put is complete: \(String(describing: downloadMetadata))")
}
the line I am having issued with is the
'guard let imageData =
imageView.image?.jpegData(compressionQuality:
0.75) else { return }'
error received : 'jpegData(compressionQuality:)' has been renamed to
'UIImageJPEGRepresentation(::)'
code is changed to
'guard let imageData =
imageView.image?.UIImageJPEGRepresentation(compressionQuality:
0.75) else { return }
enter image description hereerror received : Value of type 'UIImage' has no member
'UIImageJPEGRepresentation'
any ideas?