1

I have imported the following: import FirebaseAuth import Firebase import FirebaseFirestore import FirebaseDatabase

I am trying use this line of code let currentUserDoc = snapshot?.documents.first(where: { ($0["uid"] as? String) == UserId }) but xcode says "Use of unresolved identifier 'snapshot'. What does that mean and how do I fix it so it disappears.

Jei
  • 49
  • 8
  • What is snapshot equal to? – Peter Haddad Jan 04 '20 at 08:53
  • What is snapshot usually equal to? I always find it in the StackOverflow answers, but I do not know what it's referring to. For example, the answer in this link uses it too. https://stackoverflow.com/questions/58470066/grab-the-current-users-first-name-cloud-firebase-swift – Jei Jan 04 '20 at 10:38
  • did you try the answer? – Peter Haddad Jan 05 '20 at 11:28

1 Answers1

1

You need to use getDocuments():

var userName = db.collection("users").getDocuments() { (snapshot, error) in
        if let error = error {
            print("Error getting documents: \(error)")
    } else {
        //do something
            let currentUserDoc = snapshot?.documents.first(where: { ($0["uid"] as? String) == UserId })

            }
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134