2

How to assign TimeStamp using FieldValue.serverTimestamp() it returns FSTServerTimestampFieldValue: 0x6000024ee0e0 as debugPrint(FieldValue.serverTimestamp()) shows in debug menu

Code here

let db = Firestore.firestore()
    let settings = db.settings
    settings.areTimestampsInSnapshotsEnabled = true
    db.settings = settings        
    db.collection(THOUGHTS_REF).addDocument(data: [

        CATEGORY : categorySelected,
        NUM_COMMENTS : 0,
        NUM_LIKES : 0,
        THOUGHT_TXT : thoughtTxt.text!,
        TIMESTAMP : FieldValue.serverTimestamp(),
        USERNAME : username


    ]) { (err) in
        if let err = err {
            debugPrint("Error adding document: \(err)")
            return
        }
    }
    self.navigationController?.popViewController(animated: true)
}
Usama
  • 336
  • 1
  • 14
  • It must be used as the value for a document field. The server will assign the value - the client doesn't see the value until after it's written. – Doug Stevenson Oct 31 '18 at 18:54
  • and how can I assign timestamp to document field in current scenario? @Doug Stevenson – Usama Oct 31 '18 at 19:06

1 Answers1

5

As far as I know, there is currently no way to immediately show the timestamp. The server-side timestamp is only generated on server and is null until the response from the server comes back. That's why you also get that response.

I read an article a few months ago, where it was said that there is work under way to make the client estimate the timestamp straight away. Once that feature will be released, you'll be able to get two events, similar to how Firebase Realtime Database works. First event will contain a local estimate of the timestamp, the second event will contain the actual confirmed timestamp from the server.

Paul Beusterien
  • 27,542
  • 6
  • 83
  • 139
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193