4

I want to unpin a list of objects, which I had successfully locally stored earlier, and replace it with a new one. The code below should do that trick, but the locally pinned objects simply don't get updated. I tried everything including PFObject.unpin, nothing removes the old pinned objects except a complete reset of the simulator

func updateCountryList(server:Int, local:Int) {
    let query = VEPCountry.queryAll()
    query.findObjectsInBackgroundWithBlock {
        (objects: [AnyObject]!, error: NSError!) -> Void in
        if error != nil {
            // throw error
        } else {
            if local != 0 {
                VEPState.unpinAllObjectsWithName(String("countryListVersion\(local)"))
            }
            VEPState.pinAll(objects, withName: String("countryListVersion\(server)"))
            defaults.setObject(server, forKey: "localCountryListVersion")
        }
    }
}

Appreciate help or pointer to known issues around unpinning in Swift

Christof
  • 61
  • 1
  • what version are you using? – soulshined Feb 12 '15 at 20:03
  • Parse iOS SDK 1.6.2 -> the latest, if I'm not mistaken – Christof Feb 13 '15 at 20:18
  • Why are the pin names different for the unpin and pin methods? – hhanesand Feb 16 '15 at 06:15
  • I use a new pin name for the next set, so next time round the new pin is the old pin for unpinning. Shouldn't make a difference. I also tried with the same name, and the problem didn't go away – Christof Feb 17 '15 at 15:40
  • same problem as you. Unpin is not working. I tried with instance method and static one. It change nothing. My object is still present when I query the local storage... any solution ? – Dragouf Apr 23 '15 at 12:10
  • no, not yet. I'm still praying for a solution falling from the sky :) Have been working days on it... I also uninstalled and reinstalled the app, but the local datastore seems to be kept... – Christof Apr 24 '15 at 13:10
  • Still no solution? same problem here – Bogdan Pop Aug 19 '15 at 18:59

1 Answers1

0

I wonder if your unpin has't really finished, it's going off to the database after all.

Can you try:

query
  .findObjectsInBackground()
  .continueWithSuccessBlock({ (task: BFTask!) -> AnyObject! in
    // ...
    return VEPState.unpinAllObjectsWithNameInBackground("name"))
  })
  .continueWithSuccessBlock({ (task: BFTask!) -> AnyObject! in
    // ...
    return VEPState.pinAllInBackground(objects, withName: "name"))
  })

I may have the syntax a little off and the background method names not quite right. Also I'm using promises/tasks which is not a bad habit to get into.

Scott McKenzie
  • 16,052
  • 8
  • 45
  • 70