ello, i'm running a query to Firebase and i need to get the document ID of the collection. This is the code to run the query:
Variable
private var ptListInCell = [PTList]()
@IBAction func getDataTapped(_ sender: Any) {
SVProgressHUD.show()
if HOSP != (hospnameTxt.text!) {
ptListQuery = ptListCollectionRef?.whereField("hosp", isEqualTo: (hospnameTxt.text!))
}
ptListQuery?.getDocuments { (snapshot, error) in
if let err = error {
debugPrint("error getting data: \(err)")
} else {
guard let snap = snapshot else { return }
for document in snap.documents {
let data = document.data()
let ptName = data[PTNAME] as? String ?? ""
let assignedMd = data[ASSIGNEDMD] as? String ?? ""
let officeMd = data[OFFICEMD] as? String ?? ""
let assignedDate = data[ASSIGNEDDATE] as? String ?? ""
let seeNoSee = data[SEENOSEE] as? String ?? ""
let room = data[ROOM] as? String ?? ""
let app = data[APP] as? String ?? ""
let documentId = document.documentID
print("documentId", documentId)
let newPtList = PTList(ptName: ptName, assignedMd: assignedMd, officeMd: officeMd, assignedDate: assignedDate, seeNoSee: seeNoSee, room: room, app: app, documentId: documentId)
print("newPtList", newPtList)
print("documentId", documentId)
self.ptListInCell.append(newPtList)
}
}
it pulls everything but the documentID. When i print to the console:
print(ptlist?.documentId asAny)
Result is nil.
thank you!