iOS Parse - 删除&更新记录

时间:2015-12-29 11:38:34

标签: ios swift parse-platform

我正在开发一个执行多个程序的iOS应用程序。其中一个程序是注册用户。总的来说,这个过程目前需要大约7个请求来解析后端才能完成。我正在尝试优化请求数量,即减少它们。

我有这个代码,基本上检查Parse类中的数组值是否为空。如果不是空的,那么我将其清空并在之后发出另一个请求以添加新值。如何在单个请求中进行此操作?即要求擦除Parse类中的数组列的当前值并将两个元素插入此数组(纬度和经度)?

一些负责操作的代码

/*To clear existing values in array*/
            let query = PFQuery(className:"_User")

            query.getObjectInBackgroundWithId(PFUser.currentUser()!.objectId!) {
                (gameScore: PFObject?, error: NSError?) -> Void in
                if error != nil {
                    print(error)
                } else if let gameScore = gameScore {
                    print("No Errors.........")
                    gameScore.removeObjectsInArray(self.tempWorkAddressValues, forKey: "workAddress")
                    print("Step 1 Completed")
                    gameScore.saveInBackground()
                    print("successfully cleared array")
                }
            }

            /*to add new elemnets to array*/
            let query2 = PFQuery(className:"_User")

            query2.getObjectInBackgroundWithId(PFUser.currentUser()!.objectId!) {
                (gameScore: PFObject?, error: NSError?) -> Void in
                if error != nil {
                    print(error)
                } else if let gameScore = gameScore {
                    print("No Errors.........")
                    gameScore.addObjectsFromArray(self.userObject.workAddress, forKey: "workAddress")
                    print("Step 2 Completed")
                    gameScore.saveInBackground()
                    print("successfully updated array")
                    self.performSegueWithIdentifier("addressWorkBackToProfileSegue", sender: sender);

                }
            }

感谢您的帮助。

0 个答案:

没有答案