2

I would like to delete an object from Parse when I un-check the table row.

The issue occurs when trying to delete objects from Parse after having queried them.

this is my code:

   if  cell.accessoryType == UITableViewCellAccessoryType.Checkmark {
            cell.accessoryType = UITableViewCellAccessoryType.None

            var query = PFQuery(className:"Followers")
            query.whereKey("follower", equalTo: "\(PFUser.currentUser()?.username)")
            query.whereKey("following", equalTo: "\(cell.textLabel?.text)")

            query.findObjectsInBackgroundWithBlock {
                (objects: [AnyObject]?, error: NSError?) -> Void in
                if error == nil {

                    for object in objects as! [PFUser] {

                        object.deleteInBackground()
                    }

                } else {
                    println(error)
                }
            }


        }
13
  • Can you use Xcode to place a breakpoint to see if deleteInBackground is getting called? Commented Aug 17, 2015 at 15:54
  • i checked with println and it "s not getting called... Commented Aug 17, 2015 at 15:56
  • Can you check that objects.count != 0? Or can you atleast see what is getting called? Commented Aug 17, 2015 at 15:58
  • yes i println objects and the objects appeares... Commented Aug 17, 2015 at 15:59
  • Do your user class ACLs permit this operation? Commented Aug 17, 2015 at 16:01

2 Answers 2

4

I think the issue is in your query.findObjectsInBackgroundWithBlock i think its because you are defining objects as! [PFUser] instead of a [PFObject]

try this it should do the trick

query.findObjectsInBackground { (objects, error) in
        if error == nil,
            let objects = objects {
            for object in objects {
                object.deleteInBackground()
            }
        }
Sign up to request clarification or add additional context in comments.

Comments

0

I want to delete objects from parse

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:

query.findObjectsInBackgroundWithBlock({ (objects : [PFObject]?, error: NSError?) -> Void in
    PFObject.deleteAll(inBackground: objects)
})

You can also see this post

I hope my answer was helpful 😊

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.