I'm using Parse and MongoDB for my app, and I have a problem concerning PFFile. I would like to save an empty PFFile on the server. Indeed, the user doesn't have to send a picture but in an other way, it's possible.
I would like to set a default PFFile which is null.
let imageFile: PFFile?
if previewImg.image != nil {
// Send pic to server after converting to FILE and compression
let imageData = UIImageJPEGRepresentation(previewImg.image!, 0.5)
imageFile = PFFile(name: "step.jpg", data: imageData!)
} else {
imageFile = ""
}
object["stepImg"] = imageFile
This is my code. And my error is "cannot assign value of type string to type PFFile".
Do you have an idea about how I can do that ?
You declare a PFFile?
so your variable can a PFFile or nil
This is the corrected code
let imageFile: PFFile?
if let previewImage = previewImg.image {
// Send pic to server after converting to FILE and compression
let imageData = UIImageJPEGRepresentation(previewImage, 0.5)
object["stepImg"] = PFFile(name: "step.jpg", data: imageData!)
}