How can I fix "Argument passed to call that takes no arguments" on function in Swift using FirebaseFirestoreSwift?

Viewed 207
func fetchUser() {
  guard let uid = userSession?.uid else { return }

  Firestore.firestore().collection("users").document(uid).getDocument { snapshot, _ in
    guard let user = try? snapshot?.data(as: User.self) else { return }
    self.currentUser = user
 }
}

The error is thrown on the "guard let user" line. Any idea on how to fix this error? Also, I am not using Cocoapods ... I am using Firebase from the github sdk

2 Answers

it seems you are missing the "documents" step, could you try something like this:

func fetchUser() {
    guard let uid = userSession?.uid else { return }
    
    Firestore.firestore().collection("users").document(uid).getDocument { snapshot, _ in
        guard let docs = snapshot else { return }
        for doc in docs.documents {
            let user = doc.data(as: User.self)
            self.currentUser = user
            // break as required or just get the first in documents
        }
    }
}

You need to ensure that you have:

import FirebaseFirestoreSwift

With this the data(as: ) function, it should work.

Related