Ryan Ryan - 5 months ago 6
Swift Question

Ambigious use of 'Key'

I am trying to print the Key name of a piece of data from Firebase using swift but I keep getting 'Ambigious use of Key' when I type something like:

for child in snapshot.children{
print(child.key)
}


How can I avoid this? All help is appreciated very much!

Answer

Cast it as FIRDataSnapshot. Try doing this:

for child in snapshot.children{
 let child1 = child as! FIRDataSnapshot
        print(child1.key)
}