2017-01-06 1 views
0

パーズローカルデータストアにデータを集めていますが、新しいテーブルを固定する前に古いテーブルを削除します。問題はそれが削除されているようではないと私は同じテーブルの複数のエントリを終了します。パースローカルデータストアからオブジェクトを削除する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」プロパティを使用して作業することはできません。問題のテーブルを特に照会している関数を呼び出すだけです。それはうまく動作しますが、私の元のコードが動作していない理由を誰かが知っている場合、知っていることを愛する。上記のすべての固定を解除する代わりに

コールこの:

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) 

      } 
     } 
} 

答えて

0
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) 

     } 
    } 
}