0

I am developing an app in Xcode using swift and am using a heroku-hosted parse-server as my database. I want to be able to delete an object from the database, but I keep getting an error when trying to type out the code. Here is what I have:

{
        let removingObjectQuery = PFQuery(className: "GoingTo")
        removingObjectQuery.whereKey("objectId", equalTo: goingToSelectionID)
        removingObjectQuery.findObjectsInBackground(block: { (object, error) in
            if let objects = object{
                print("Object found")
                for object in objects{
                        object.deleteInBackground()  
                }
            }
        })
    }

But the delete .deleteInBackground keeps sending an error to in the code line saying that ".deleteInBackground is not a member of [PFObject]"... except that I thought it is a member of that value type?

Edit: Syntax fixed to allow calling of .deleteInBackground but now am receiving error in logs (which does not crash the app) that "[Error]: Object not found". The object is for sure in the DB and whereKey equalTo: is adequately described... (goingToSelectionID is indeed the objectId in the DB... checked this by printing to logs). Not sure what is wrong?

1 Answer 1

1

The findObjectsInBackground method doesn't return results of type PFObject, but [PFObject], which is an array of PFObjects... If you want to delete the whole array, you can use the class method deleteAllInBackground like so:

PFObject.deleteAllInBackground(objectt, block: nil)

Or you can iterate through the array:

for objectt in object! {
    objectt.deleteInBackground()
}
Sign up to request clarification or add additional context in comments.

3 Comments

I edited to the question with the fixed syntax. The call works, but now I am receiving another error... telling me that the object is not found (despite the variable in the whereKey that is equalTo: for sure matching the objectId in the DB). Any ideas?
So, none of the objects in the array were deleted?
No, I have posted another question regarding the issue (because it is related but asking a different question) here: stackoverflow.com/questions/39844324/…

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.