简体   繁体   English

解析本地数据存储区:Swift中的Unpin对象似乎已被破坏

[英]Parse Local Datastore: Unpin objects seems broken in Swift

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 我尝试了包括PFObject.unpin在内的所有内容,除了完全重置模拟器外,没有任何东西会删除旧的固定对象

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 感谢帮助或指向Swift中的unpinning周围的已知问题

I wonder if your unpin has't really finished, it's going off to the database after all. 我想知道你的unpin是否真的没有完成,毕竟它会进入数据库。

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. 我也在使用承诺/任务,这不是一个坏习惯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM