I have been having a lot of trouble trying to get my photo picker to pick an image, cast it as a Pffile, then upload it to Parse.
I have currently taped together what I have so I could see it being something simple that I can't see.
The error I get is:
reason: 'PFObject values may not have class: UIImage'
Any Ideas?
@IBAction func selectUser(sender: AnyObject) {
let photoPicker = UIImagePickerController()
photoPicker.delegate = self
photoPicker.sourceType = .PhotoLibrary
self.presentViewController(photoPicker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
let imageData = UIImageJPEGRepresentation(image, 0.05)
let imageFile = PFFile(name:"image.jpg", data:imageData!)
picSlot.file = imageFile
let currentUser = PFUser.currentUser()
if currentUser != nil {
PFUser.currentUser()?.setObject(image, forKey: "userPic")
}
self.dismissViewControllerAnimated(false, completion: nil)
}
You should use the following:
You can't explicitly set the UIImage as a member of the PFObject, but you can set a PFFile as a PFObject's attribute.