Parse Unpin Does Not Remove Object From Local Datastore

This should work.

Here is one of many attempts to get this figured out

  • Parse - Setting device token
  • What does @NSManaged do?
  • Swift: Could not find an overload for '|' that accepts the supplied arguments
  • Two Query Constraints On One Key with Parse and Swift
  • How do I get parse to play a certain song when a button in the cell is clicked?
  • How to get list of all Facebook Friends when using Parse?
  •             myTrainingSessions[indexPath.row].unpinInBackgroundWithBlock{ (succ, e) -> Void in
                if succ == true {
                    // just remove from table view etc
                    self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
                    // Shows that my object is still in datastore!
                    // object should be UNPINNED - but appers in this result....
                    var query = PFQuery(className:TrainingSession.parseClassName())
                    query.whereKey(self.userType(), equalTo: PFUser.currentUser())
                    query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
                        if error != nil { return }
                        if let result = objects as? [TrainingSession] {
                            println("local results")

    I do a query after unpinning and the object is still there.

    4 Solutions Collect From Internet About “Parse Unpin Does Not Remove Object From Local Datastore”

    I’ve contacted the support team about the problem where you can’t unpin an object that has a referenced object, so I’m sharing the thread for those interested:

    The support person said it was By Design, but upon my request to improve this specification, he told me he would tell the team about it.

    One of the reasons this is not working for you is because there might still be objects in your local datastore that have relation with the object you want to unpin. To do this properly, unpin all those objects first and then unpin the target object.

    I got this to work but using the follow workflow.

    When I create a new object, and am ready to save I do the following 2 steps

        newThing.pinInBackgroundWithBlock { (res, errn) -> Void in
            // pinning is required for offline delete to work correct
            if errn != nil { return }
            //self.presentingViewController?.dismissViewControllerAnimated(true, completion: { () -> Void in
                // dismiss modal if required...

    Within my tableview I delete like this

    override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        if editingStyle == .Delete {
            self.myDataSource.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)

    Fetching process, within the same tableview

    1. Local Query – from local datastore – this directly updates my tableview – called first
    2. Network Query – this does the unpinning and pinning, updates the tableview data source – once completed this calls the local Query again to update the table.

    Here is my network query

    func networkQuery() {
        let nquery = theQuery()
        nquery.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
            if let temp = objects as? [YourObjectType] where error == nil {
                PFObject.unpinAllInBackground(self.myDataSource, block: { (resultBool, error) -> Void in
                    if error != nil { return }
                    PFObject.pinAllInBackground(temp, block: { (resultBool, error) -> Void in
                        if error != nil { return }

    I have tried to break this creating new items, on and offline – deleting items on and offline – all works. Hope it helps, couldn’t find any examples online so only go it to work with trail and error…. painful process, but working like a charm now.

    After doing R & D on
    I come to know that you can unpin objects from local storage once they are stored on cloud. B’coz parse is basically used for storing data on cloud so it allow unpinning of data after storing on cloud.

    - (void)syncDataToCloud:(id)sender {
        PFQuery *qry = [PFQuery queryWithClassName:@"Person"];
        [qry fromLocalDatastore];
        NSArray *arr = [qry findObjects];
        [PFObject saveAllInBackground:arr block:^(BOOL succeeded, NSError *error) {
            if (succeeded) {
                DisplayAlert(@"Sync successful.");
            } else {
                DisplayAlert(@"Sync unsuccessful");
        [PFObject unpinAll:arr];

    it works for me…!! 🙂