简体   繁体   English

更新Parse.com中的createdAt列

[英]Update the createdAt column in Parse.com

When uploading a file to Parse.com , the createdAt column get set automatic. 当需要上传文件到Parse.comcreatedAt列获取设置自动。

I want to update the createdAt time, to the current time this func get set: 我想将createdAt时间更新为该功能的当前时间:

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() self.currentDateTime来自: let currentDateTime = NSDate()

But somehow, the createdAt does not change at all.. How come? 但是不知何故, createdAt根本不会改变。 Any tips? 有小费吗?

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

I am sorry, but the field createdAt and updatedAt cannot be modified manually; 我很抱歉,但是场createdAtupdatedAt不能手动修改; https://www.parse.com/questions/can-i-modify-the-field-createdat 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 . Parse.com中创建一个新列,命名为ex: modifiedAt作为NSDate
  2. Change your code gameScore["createdAt"] to gameScore["modifiedAt"] . 将您的代码gameScore["createdAt"]更改为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. 现在,该字段将被更新为与createdAt相同的格式,并且您可以根据需要轻松地更新列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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