Skip to content

Instantly share code, notes, and snippets.

@KrauserHuang
Created March 29, 2021 09:25
Show Gist options
  • Save KrauserHuang/3dd402ad8cb55db00a5bdcb3b15df1a9 to your computer and use it in GitHub Desktop.
Save KrauserHuang/3dd402ad8cb55db00a5bdcb3b15df1a9 to your computer and use it in GitHub Desktop.
func loadUser() {
db.collection(Constant.FireStore.users).getDocuments { (querySnapshot, error) in
if let error = error {
print("There was an issue retrieving data to Firestore. \(error)")
} else {
if let snapshotDocuments = querySnapshot?.documents {
for doc in snapshotDocuments {
let data = doc.data()
if let userName = data[Constant.FireStore.userName] as? String {
// label顯示速度有差,再確認
DispatchQueue.main.async {
self.welcomeLabel.text = "Welcome, \(userName)"
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment