user7222919 user7222919 - 4 years ago 103
iOS Question

Saving an array of images

Is it possible to save an array of images under one field-name in mlab.com/heroku. I'm trying to save 150 images in one field-name. I know how to save one image. But is it possible to save 150+ in one field-name.

Answer Source

You can't save an array of 'images', as in PFFiles, but you can save an array of PFObjects. So create an array of PFObjects, each with the same class name, each with a PFFile assigned to the same field name in that PFObject, then save like so:

PFObject.saveAll(inBackground: myObjects, block: { result, error in

})

Then you'll also be able to retrieve all those files as well via retrieving the PFObjects

EDIT

Here is a quick sloppy example of how you might get started:

    let objectA = PFObject(className: "Some")
    objectsA["thumbnail"] = myPFFile1

    let objectB = PFObject(className: "Some")
    objectsB["thumbnail"] = myPFFile2

    PFObject.saveAll(inBackground: [myPFFile1, myPFFile2], block: { result, error in

    })

    PFQuery.findObjectsInBackground({ result, error in

        if let objects = result as? [PFObject], let first = objects.first, let thumbnail = first["thumbnail"] as? PFFile {
            //can do something with thumbnail
        }
    })
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download