When I run checkDoc
I'm finding that my State validDoc
will initially be set to false
, but the second time I run it the value returns true
. I know the document I'm querying for is present. I'm not sure what I'm doing wrong.
class PropertiesViewModel: ObservableObject {
@Published var validDoc= false
private var db = Firestore.firestore()
func checkDoc(docRef: String) -> Bool {
db.collection(docRef).getDocuments { (querySnapshot, error) in
if querySnapshot?.count ?? 0 > 0 {
self.validDoc = true
}
}
print("validDoc \(validDoc)")
return validDoc
}
}
Here's my return
validLogin false
validLogin true