I pass a parameter uid
to my function checkIfUserExists
and make an async call. However I am unable to access uid
within the callback of the async call.
class Database {
func checkIfUserExists(uid: String){
let db = Firestore.firestore()
db.collection("users").document(uid).getDocument { (snapshot, err) in
if let document = snapshot, document.exists {
print("User exists")
} else {
print("User does not exist, createUser()")
createUser(uid: uid)
}
}
}
}
The error:
Call to method 'createUser' in closure requires explicit 'self.' to make capture semantics explicit
Any idea how I access uid
or pass it to the async call so I can pass it to createUser()
?