更新Parse.com中的createdAt列

时间:2016-05-04 22:56:13

标签: ios swift parse-platform

将文件上传到Parse.com时,createdAt列会自动设置。

我想将createdAt时间更新为此func设置的当前时间:

let query = PFQuery(className:"NorgeStory")
        query.getObjectInBackgroundWithId(objID[(indexPath?.row)!]) {
            (gameScore: PFObject?, error: NSError?) -> Void in
            if error != nil {
                print(error)
            } else if let gameScore = gameScore {
                gameScore["isPending"] = false
                gameScore["createdAt"] = self.currentDateTime
                gameScore.saveInBackground()
                gameScore.saveInBackgroundWithBlock({ (success: Bool, error: NSError?) in
                    if (success) {
                        // The score key has been incremented
                        print("Accepted post!")

                        let alert = UIAlertView()
                        alert.title = "Innlegg godkjennt!"
                        alert.message = "Innlegget er godkjennt."
                        alert.addButtonWithTitle("OK")
                        alert.show()

                        self.queryStory()

                    } else {
                        // There was a problem, check error.description
                        print(error?.description)
                    }
                })
            }
        }

self.currentDateTime来自:let currentDateTime = NSDate()

但不知何故,createdAt根本没有变化......怎么样?有什么提示吗?

2 个答案:

答案 0 :(得分:1)

您无法更新createdAt字段(请参阅this Parse forum link,其中Parse员工说“createdAt和updatedAt字段无法手动修改”。您应该创建一个更新的新Date列代替。

答案 1 :(得分:1)

对不起,但无法手动修改字段createdAtupdatedAt; https://www.parse.com/questions/can-i-modify-the-field-createdat

尝试这样的事情:

  1. Parse.com中创建一个新列,名为ex modifiedAt NSDate
  2. 将您的代码gameScore["createdAt"]更改为gameScore["modifiedAt"]
  3. 现在该字段将以与createdAt相同的格式更新,您可以根据需要轻松更新列。