I have a fetch call is supposed to return a string, and this is how it looks:
func fetchCallTwo() -> String {
let db = Firestore.firestore()
let docRef = db.collection("path").document("subDoc")
var returnableString: String = "DEFAULT VALUE"
docRef.getDocument { (theDocument, error) in
if let document = theDocument, document.exists {
let field = document.get("field")
if let field = field {
print(field)
returnableString = "\(field)"
}
}
}
print(returnableString)
return returnableString
}
However, this always returns "DEFAULT VALUE" instead of the value I want it to return, ie, the value fetched from my firebase server.
How do I rectify this?