D. Finna D. Finna - 1 year ago 154
iOS Question

How to append without unique auto id firebase swift

I am trying to append data to my database, everytime a user is clicking a like button, if the user hasn't already clicked it. The problem is, when I am appending to the

, a unique id is showing. How can I get rid of that? Otherwise it is not possible for me to check if the user has already clicked the button?

Here is my firebase structure:
enter image description here

It is the green parts that are unique id, the black zones under the unique id are the user id, that I want to be able to check if has already clicked the button.

This is my code for appending to

let quoteString = [userId: true]
let refPhotos = FIRDatabase.database().reference().child("feed-items").child(dataPathen).child("likesForPost")
let refBase54 = refPhotos.childByAutoId()

Hope you guys can help me :-)

Answer Source

Use :-

let prntRef = FIRDatabase.database().reference().child("feed-items").child(dataPathen).child("likesForPost")
prntRef.observeSingleEventOfType(.Value, withBlock: { (snap) in

    if let favDict = snap.value as? NSMutableDictionary{
        favDict.setObject("true",forKey : uid)
    } else {

Or But this is just a HACK!


For more options check:- http://stackoverflow.com/a/39458044/6297658

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download