将UIImage上传到Parse

时间:2016-03-02 21:54:30

标签: ios swift parse-platform uiimage pfimageview

我一直在努力让我的照片选择器选择图像,将其作为Pffile投射,然后将其上传到Parse。

我现在把我所拥有的东西录在一起所以我可以看到它是一种简单的东西,我无法看到。

我得到的错误是:

原因:' PFObject值可能没有类:UIImage'

任何想法?

@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)


}

1 个答案:

答案 0 :(得分:0)

您应该使用以下内容:

if currentUser != nil {
    PFUser.currentUser()?.setObject(imageFile, forKey: "userPic")
}

您无法将UIImage显式设置为PFObject的成员,但您可以将PFFile设置为PFObject的属性。