How to insert firebase server timestamp using iOS SDK in Swift project

In the "stand-alone features" section of the iOS manual , it mentions kFirebaseServerValueTimestampthat does not seem to work in the Swift project (autocomplete does not request).

I tried [".sv": "timestamp"]how the Swift example did it. But he complains that this cannot be established with other values ​​and should be the only value for this path.

What I wanted to do was save the created timestamp along with other values ​​for the object. And I would rather use server time to avoid skewing client clocks.

How can i do this?

+4
source share
2 answers

".sv":"timestamp" [ ], Firebase.

:

let objectToSave: Dictionary <String: AnyObject> = ["date": [".sv": "timestamp"], "key1": "value1", "key2": 1234.....] 

Firebase :

date: 1463329843759

Firebase

+10

Firebase 4.0 ServerValue.timestamp()

:

    let ref = Database.database().reference().child("userExample")
    let values = ["firstName": "Joe", "lastName": "Bloggs", "timestamp": ServerValue.timestamp()] as [String : Any]

    ref.updateChildValues(values) { (err, ref) in

        if let err = err {
            print("failed to upload user data", err)
            return
        }

    }
+2

All Articles