StructureName.getDocument("Users", "") { (document, gotDocument) in
if gotDocument {
print("Success")
} else {
print("Error while getting Document")
}
}
public static func getDocument(_ collectionName: String, _ documentId : String, completion: @escaping(_ documentSnapShot : DocumentSnapshot,_ success : Bool) -> Void) {
SVProgressHUD.show()
let User = Auth.auth().currentUser
guard let user = User else {
SVProgressHUD.dismiss()
return
}
var docID = ""
if documentId == "" {
docID = user.uid
} else {
docID = documentId
}
let db = Firestore.firestore()
db.collection(collectionName).document(docID).addSnapshotListener { (document, error) in
if error != nil {
print("Error :", error as Any)
SVProgressHUD.dismiss()
return
}
guard let document = document else {
print("Error While Getting Document")
SVProgressHUD.dismiss()
return
}
completion(document, true)
}
}