Swift Delete multiple objects at once Parse server

ε祈祈猫儿з 提交于 2019-12-10 06:02:43

问题


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.


回答1:


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 😊



来源:https://stackoverflow.com/questions/43313901/swift-delete-multiple-objects-at-once-parse-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!