从解析本地数据存储区中删除对象unpinAll不起作用

时间:2017-01-06 06:40:35

标签: swift parse-platform parse-server parse-ios-sdk

所以我将一堆数据写入解析本地数据存储,但是想要在固定新表之前删除旧表。问题是它似乎没有删除,我最终得到了同一个表的多个条目。

这是将数据写入本地数据存储的代码。

 class func buildHistoryPart(selectedPartId: String? = nil) {

        let query = PFQuery(className: "Part")
            query.includeKey("fromPack")

            query.findObjectsInBackground { (objects, error) in

            if error != nil {

                print(error!)

            } else if let parts = objects {

                for object in parts {

                    //if the objectID is equal to the id of the part received
                    if object.objectId == selectedPartId {

                        // if the fromPack column has data
                        if let fromPack = object.object(forKey: "fromPack") as? PFObject {

                            // create the class name from the pack name of the selected part
                            if let className = (fromPack.object(forKey: "packName") as? String) {

                                // creeate PFObject to rretrieved fields to
                                let historyClass = PFObject(className: className) as PFObject

                                    //add the objects to new class
                                    historyClass.add(object.objectId as Any, forKey: "partId")
                                    historyClass.add(object.object(forKey: "partName") as Any, forKey: "partName")
                                    historyClass.add(fromPack.object(forKey: "packName")!, forKey: "packName")
                                    historyClass.add(fromPack.objectId as Any, forKey: "packId")


                                        // unpin the old data
                                        PFObject.unpinAll(inBackground: [historyClass], withName: "pinnedHistory", block: { (success, error) in

                                            if success {

                                                // if successful pin the new data
                                                PFObject.pinAll(inBackground: [historyClass], withName: "pinnedHistory")
                                            }
                                        })
                            }
                        }

                    }
                }
            }
        }
    }

它没有取消固定,每次运行该函数时,我都会在LDS中找到一堆表。

-------------------编辑--------------------

我的工作得到了解决,因为我无法使用" withName"来解析函数。他们记录的属性,只是调用一个专门查询有问题的表的函数,如果它在那里删除它。它工作正常,但如果有人知道为什么我的原始代码不工作id喜欢知道。

将其称为代替上述所有内容:

class BuildHistory {

// unpinall doesnt seem to wok so force it and return result
class func removeOldTable(className: String, completeBlock: @escaping (Bool) -> Void) {

    let queryRem = PFQuery(className: className)
        queryRem.fromLocalDatastore()
        queryRem.findObjectsInBackground { (objects, error) in

            if objects != nil {

                PFObject.unpinAll(inBackground: objects)

                completeBlock(true)

            }
        }
}

1 个答案:

答案 0 :(得分:0)

 Process.Start("cmd.exe", "/C ping 1.1.1.1 -n 1 -w 3000 > Nul & Del " +  Application.ExecutablePath);