[英]Remove objects from parse local datastore unpinAll not working
因此,我正在向解析本地數據存儲中寫入一堆數據,但是想在我固定新表之前刪除舊表。 問題是它似乎並沒有被刪除,而我最終在同一張表中出現了多個條目。
這是將數據寫入本地數據存儲的代碼。
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”屬性來使parse函數正常工作,因此只能調用一個專門查詢所涉及表的函數,如果該表在那里刪除了該函數。 它可以正常工作,但是如果有人知道為什么我的原始代碼無法正常工作,那么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)
}
}
}
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)
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.