Your newDoc
is a DocumentReference
object, which is nothing more than a reference to a (potential) document in the database.
To load the document from the database you need to call getdocument()
on the reference, as shown in this snippet from the documentation:
let docRef = db.collection("cities").document("SF")
docRef.getDocument { (document, error) in
if let document = document, document.exists {
let dataDescription = document.data().map(String.init(describing:)) ?? "nil"
print("Document data: (dataDescription)")
} else {
print("Document does not exist")
}
}
The data is only available within the completion handler, as shown above. Trying to access it outside of there will lead to timing problems, as the data is loaded asynchronously.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…