0
votes

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.

1
Maybe there was a quota reach? Are the database nodes available for you to view?Max Kraev
@MaxKraev I apologize I am really new to coding as a whole. I do not know what, or where that isuser9965399
I’m glad you found your answer)Max Kraev

1 Answers

0
votes

If your app use login and logout try to comment lines who has errors, build and run to be able to logout from the app, then rebuild the app with the original code, login and it should be ok

If you’re not using login page try to clean your project (cmd shift k)