Add timestamp in Firestore documents

前端 未结 10 1010
旧巷少年郎
旧巷少年郎 2020-12-29 03:29

I\'m newbie to Firestore. Firestore docs says...

Important: Unlike \"push IDs\" in the Firebase Realtime Database, Cloud Firestore au

10条回答
  •  时光取名叫无心
    2020-12-29 04:28

    Try this one for Swift 4 Timestamp(date: Date())

    let docData: [String: Any] = [
    "stringExample": "Hello world!",
    "booleanExample": true,
    "numberExample": 3.14159265,
    "dateExample": Timestamp(Date()),
    "arrayExample": [5, true, "hello"],
    "nullExample": NSNull(),
    "objectExample": [
        "a": 5,
        "b": [
            "nested": "foo"
        ]
    ]
    ]
    db.collection("data").document("one").setData(docData) { err in
    if let err = err {
        print("Error writing document: \(err)")
    } else {
        print("Document successfully written!")
    }
    }
    

提交回复
热议问题