Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Delete multiple objects at once Parse server

I query to the server following

let query = PFQuery(className: "posts")
            query.whereKey("uuid", equalTo: Ncell.uuidLbl.text!)
            query.findObjectsInBackground { (objects:[PFObject]?, error:Error?) in
                if error == nil {
                    for object in objects! {
                        object.deleteInBackground(block: { (success:Bool, error:Error?) in
                            if success{

                            }
                        })
                    }
                }
            }

Rather than using a loop and deleting each object individually, I want to know if it would be possible to delete all the found objects at once to save on requests.

like image 765
user6520705 Avatar asked Apr 10 '17 01:04

user6520705


1 Answers

I want to know if it would be possible to delete all the found objects at once

Yes in the Parse iOS SDK to delete multiple objects in background at once on Parse server, you can use deleteAllInBackground

You can use it with 2 different ways:

PFObject.deleteAll(inBackground: [PFObject]?)
PFObject.deleteAll(inBackground: [PFObject]?, block: PFBooleanResultBlock?)

For example:

let query = PFQuery(className: "posts")
query.whereKey("uuid", equalTo: Ncell.uuidLbl.text!)
query.findObjectsInBackground { (objects:[PFObject]?, error:Error?) in
    if error == nil {
        PFObject.deleteAll(inBackground: objects, block: { (success:Bool, error:Error?) in
                if success {

                }
            })
        }
    }

I hope my answer was helpful 😊

like image 80
Julien Kode Avatar answered Nov 18 '22 19:11

Julien Kode