Ambiguous use of 'observSingleEvent (from: with :)

I am trying to get profile pictures of some users. Here is the code that I start with:

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

I try to follow the Swift 2 tutorial; however, I am using Swift 3. I already tried to set up the code, but I was not successful since I got the following error

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

This error is on the first line. How can i solve this? Thanks!

+6
source share
2 answers

Working solution for Swift 3:

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

The problem here is with the block at the end of this line:

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

since there are many implementations of the observeSingleEvent function, the compiler becomes a observeSingleEvent one to choose.

Decision:

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

Hope this helps someone

+1
source

All Articles