I'm trying to Grab all Fields as dictionary from 1 document. But when I try to do it i just get returned with empty array. I tried getting help from documentation and it's not working.
tho this line of code shows it not empty
print("Cached document data: (dataDescription)")
var user:String = (Auth.auth().currentUser?.email)! // I used email as name of document.
var Groups = [String:Any]()
let docRef = AppDelegate.db.collection("JoinedGroups").document(user)
docRef.getDocument(source: .cache) { (document, error) in
if let document = document {
let dataDescription = document.data()
self.Groups = dataDescription! // unwrapping here
print("Cached document data: \(dataDescription)")
} else {
print("Document does not exist in cache")
}
}
// Do any additional setup after loading the view.
print(Groups)
}
Here are my results: document.data() is shown as dictionary when i hoover over definition
[:] //Shown as empty??
Cached document data: Optional(["test new": test new, "g3": g3, "g1": g1])
Thank You very much if i can get some help on this issue.