简体   繁体   中英

Update the createdAt column in Parse.com

When uploading a file to Parse.com , the createdAt column get set automatic.

I want to update the createdAt time, to the current time this func get set:

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

The self.currentDateTime is from: let currentDateTime = NSDate()

But somehow, the createdAt does not change at all.. How come? Any tips?

您无法更新createdAt字段(请参阅此Parse论坛链接 ,其中Parse员工说“ createdAt和updatedAt字段无法手动修改”。您应该创建一个新的Date列,而应进行更新。

I am sorry, but the field createdAt and updatedAt cannot be modified manually; https://www.parse.com/questions/can-i-modify-the-field-createdat

Try something like this:

  1. Create a new column in Parse.com , named ex: modifiedAt as an NSDate .
  2. Change your code gameScore["createdAt"] to gameScore["modifiedAt"] .

Now that field will be updated as the same format as createdAt , and you can easy update the column as you would like.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM