I am trying to save images from Parse to a list. Now I am saving the images as PFFileObject, but I want to save them as uiimages instead. I am using this code:
var weblinks = [String]()
var webnames = [String]()
var webobjects= [PFFileObject]()
var webimages = [UIImage]()
func fetchFromParse() {
let query = PFQuery(className:"FirstClass")
query.findObjectsInBackground { (objects, error) -> Void in
if error == nil {
for object in objects! {
self.webnames.append(object["webnames"]! as! String)
self.weblinks.append(object["weblinks"]! as! String)
self.webimages.append(object["webobjects"]! as! PFFileObject
}
self.myCollectionView.reloadData()
} else {
print(error!)
}
}
}
How can I do to save the images to webimages instead of webobjects?
You can't save images as
UIImagedirectly because Parse doesn't know what that is.PFFileObjectexists to help you upload any kind of file, like images, as long as its converted toData.Getting a
Dataobject from anUIImageis as simple asand you can initialize an image with a
Dataobject like thisBoth methods return optionals, so you'll have to deal with that, but you can use that
Datavalue onPFFileObjectto upload your images to Parse.