0

I have this code to display username that was stored in Firestore when signing up:

 func displayUserName(){ let db = Firestore.firestore() if let uid = user?.uid{ db.collection("PROFILE").document(uid).getDocument { (snap, err) in guard let data = snap else {return} let firstname = data.get("firstName") as! String self.firstName = firstname } } } 

but, when I change the name in Firestore, I need to relaunch the app so it can update. is it possible to update this name without needing to relaunch the app?

2
  • 1
    I don't know about switf, but uou should be able to get so called snapshot that you can listen for changes. getDocument() gets document once Commented Dec 13, 2020 at 14:14
  • Thank you, worked flawlessly. Just answered my question. Cheers Commented Dec 13, 2020 at 14:41

1 Answer 1

1

Based on the comment given, I just changed getDocuments for addSnapshotListener

db.collection("PROFILE").document(uid).addSnapshotListener { (documentSnapshot, error) in guard let datas = documentSnapshot else {return} let firstname = datas.get("firstName") as! String self.firstName = firstname } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.