Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguous use of 'observeSingleEvent(of: with:)

I am trying to get some users' profile pictures. Here is the code I am starting with:

databaseRef.child("Users").queryOrderedByKey().observeSingleEvent(of: .childAdded) { (snapshot) in

}

I am trying to follow a Swift 2 tutorial; however, I am using Swift 3. I have tried to adjust the code already, but I have not been successful as I get the following error

Ambiguous use of 'observeSingleEvent(of:with:)'

This error is on the first line. How can I resolve this? Thanks!

like image 959
Pranav Wadhwa Avatar asked Jul 27 '16 00:07

Pranav Wadhwa


2 Answers

Working solution for Swift 3:

databaseRef.child("Users").queryOrderedByKey().observe(.childAdded, with: { snapshot in

})
like image 183
Pranav Wadhwa Avatar answered Sep 28 '22 01:09

Pranav Wadhwa


The problem here with the block in the end of this line :

databaseRef.child("Users").queryOrderedByKey().observeSingleEvent(of: .childAdded) { (snapshot) in

}

since there is many implementation to the function observeSingleEvent the compiler is getting confused which to choose.

Solution:

databaseRef.child("Users").queryOrderedByKey().observeSingleEvent(of: .childAdded, 
with: { snapshot in
    // Do whatever you want with the snapshot
})

Hope this helps someone

like image 28
MBH Avatar answered Sep 28 '22 01:09

MBH