I am trying to allow the user's name to appear in the navigation bar using firebase. last night, My code worked perfectly. this morning when I tried to resume coding, my application suddenly crashes and I honestly do not know why. can someone help explain to me what I am doing wrong?
My code is as follows.
let uid = Auth.auth().currentUser?.uid
Database.database().reference().child("users").child(uid!).observeSingleEvent(of: .value, with: { (snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject] {
self.navigationItem.title = dictionary["name"] as? String
}
}, withCancel: nil)
The error message falls under Database.database().reference().child("users").child(uid!).observeSingleEvent(of: .value, with: { (snapshot) in if let dictionary = snapshot.value as? [String: AnyObject] {
// the error message is Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
again last night, the code ran perfectly. when i would create a user and log them in, their name would appear in the navigation bar. Now all of a sudden, it crashes.