Yann Massard Yann Massard - 1 month ago 23
Swift Question

firebase snapshot key for children autoids

I have the following structure :

DATA :
-kojasd- <----- child by autoid key name for folder
property:value
-kjofs- <----- child by aytoid key name for folder
property:value


how can I get the key value of the childbyautoid() in a snapshot.children loop ?

here s a bit of code to explain :

for items in snap.children {
let key = items.key as! String // DOESN T WORK

let value = items.value!!["property"] as! String


}


in this code, snap refers to DATA

I thought that it would be easy to get this key value, but I m stucked here since a long time, any help ?? :)

sincerely
Yann

Answer

ok, found a solution, I had to pass the snap into a new fdatasnapshot to get its key

Comments