'ViewController reads data from firestore late
I have username in firestore, whenever person logs in my app, I want to read that data(username) in firestore immediately, but it needs some time, if the problem is in slow internet, what other possible ways would you suggest to get my end result?

as yo can see in the gif above, loading username takes a little bit of time, but it is still a problem, I want it to be already loaded
@IBOutlet weak var welcomeNameLabel: UILabel!
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
readData()
}
func readData(){
self.db.collection("users").getDocuments{ (snapshot, err) in
if let err = err {
print("error happened \(err)")
}else {
if let userId = Auth.auth().currentUser?.uid {
if let currentUserDoc = snapshot?.documents.first(where: { ($0["uid"] as? String) == userId }) {
var welcomeName = currentUserDoc["username"] as! String
self.welcomeNameLabel.text = "Welcome, \(welcomeName)"
}
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
