0
votes

I am Implementing deleting post function. I use prepare segue myTableView pass PFObject(shown as object in code) to detail view which include deleting function. I try to use PFOBJECT's objectId to delete post, because this is unique and it is passed from original post when it is selected. This is my code,

@IBAction func deleteButtonTapped(sender: AnyObject) {

let query = PFObject(className:"Posts")

let tryToDeleteThisObjectId = object.objectId

query.objectId = tryToDeleteThisObjectId

query.deleteInBackground()

but when I activate my app, I get an error

'NSInternalInconsistencyException', reason: 'Attempted to change an objectId to one that's already known to the OfflineStore.' .

I understand object is passed as an offline, So I tried save objectId in tableView to pass detailView, it worked. however I don't want user use extra cellular data for this, and I want to find simpler way to solve this problem.

my questions are

How can I get objectId from PFobject without this error?

if I can't, is there alternative way to delete specific post(data row in parse)?

please provide me example code.

1

1 Answers

0
votes

So, the problem is that you can't call delete on a query. You have to call it on the PFObject. Try this if you want to do a query.

let query = PFQuery(className: "Class")
query.getObjectInBackgroundWithId("OBJECT_ID") { (obj, err) -> Void in
      if err != nil {
         //handle error
      } else {
          obj!.deleteInBackground()
     }
}

However, in your code I also see you called a object.id, in which case you could just call object.deleteInBackground() to delete that object.