簡體   English   中英

更新Parse.com中的createdAt列

[英]Update the createdAt column in Parse.com

當需要上傳文件到Parse.comcreatedAt列獲取設置自動。

我想將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)
                    }
                })
            }
        }

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

但是不知何故, createdAt根本不會改變。 有小費嗎?

您無法更新createdAt字段(請參閱此Parse論壇鏈接 ,其中Parse員工說“ createdAt和updatedAt字段無法手動修改”。您應該創建一個新的Date列,而應進行更新。

我很抱歉,但是場createdAtupdatedAt不能手動修改; https://www.parse.com/questions/can-i-modify-the-field-createdat

嘗試這樣的事情:

  1. Parse.com中創建一個新列,命名為ex: modifiedAt作為NSDate
  2. 將您的代碼gameScore["createdAt"]更改為gameScore["modifiedAt"]

現在,該字段將被更新為與createdAt相同的格式,並且您可以根據需要輕松地更新列。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM