title: iOS app Crashing on line Databse().reference() of Firebase
body: <p>This issue started suddenly. It had been working fine for the last couple of days authenticating with Facebook accounts. Today I tried implementing the <code>Auth.auth().createUser(email: ... password:... completion:...)</code> and suddenly my app started crashing right after authentication in function <code>func completeSignIn(id:..., userData:...)</code> at <code>DataService.ds.createFirebaseDBUser(uid: usr.uid, userData: ["provider": "Email"])</code>, it crashes in the Firebase Singleton at the line <code>Database().reference()</code>. I'm very lost. I checked out a branch where it used to work, but now it doesn't work either, so I created a new app in Firebase, but I'm getting the same issue. I've seen this question in a couple of places, but no answer. It's throwing the error: </p>
  
  <pre><code>Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: key cannot be nil'
  </code></pre>
  
  <p>but I've checked the id and the dictionary that I'm passing and the values are there. Any help is appreciated.</p>
  
  <p>Create Account code:</p>
  
  <pre><code>@IBAction func createAccount(_ sender: Any) {
      if let email = emailField.text, let pwd = pwdField.text{
          Auth.auth().createUser(withEmail: email, password: pwd, completion: { (user, error) in
              if error != nil {
                  print("Unable to Authenticate E-mail with Firebase - Error: \(String(describing: error))")
              }else{
                  print("Successfully Authenticated E-mail with Firebase")
                  if let usr = user {
                      let keychainResult = KeychainWrapper.standard.set(usr.uid, forKey: KEY_UID)
                      print("Data saved to Keychain: \(keychainResult)")
                      DataService.ds.createFirebaseDBUser(uid: usr.uid, userData: ["provider": "Email"])
                  }
              }
          })
      }
  }
  </code></pre>
  
  <p>FBLogin and Email Auth:</p>
  
  <pre><code>@IBAction func facebookLogin(_ sender: Any) {
      print("Start Login Process")
      let fbLogin = FBSDKLoginManager()
      print("Set Read Permissions")
      //TODO: add Read Permissions
      fbLogin.logIn(withReadPermissions: ["email","user_location"], from: self) { (result, error) in
          if error != nil{
              print("Unable to provide Authentication with Facebook - \(String(describing: error))")
          }else if result?.isCancelled == true{
              print("User Cancelled FB Authentication")
          }else {
              print("User Successfully Logged In")
              let credential = FacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current().tokenString)
              self.firebaseAuth(credential)
          }
      }
  
  }
  
  @IBAction func emailLogin(_ sender: Any) {
      if let email = emailField.text, let password = passwordField.text{
          Auth.auth().signIn(withEmail: email, password: password, completion: { (user, error) in
              if error != nil{
                  print("Unable to Authenticate Firebase - \(String(describing: error))")
              } else {
                  print("Succesfully authenticated with Firebase")
                  if let user = user{
                      let userData = ["provider": "email"]
                      self.completeSignIn(id: user.uid, userData: userData)
                  }
              }
  
          })
      }
  }
  
  
  func firebaseAuth(_ credential: AuthCredential){
      Auth.auth().signIn(with: credential, completion: { (user, error) in
          if error == nil {
              print("Succesfully authenticated with Firebase")
              if let user = user{
                  let userData = ["provider": credential.provider]
                  self.completeSignIn(id: user.uid, userData: userData)
              }
          } else{
              print("Unable to Authenticate Firebase - \(String(describing: error))")
          }
      })
  }
  
  
  func completeSignIn(id: String, userData: Dictionary&lt;String, String&gt;){
      DataService.ds.createFirebaseDBUser(uid: id, userData: userData)
      let keychainResult = KeychainWrapper.standard.set(id, forKey: KEY_UID)
      print("Data saved to Keychain: \(keychainResult)")
      performSegue(withIdentifier: "goToMain", sender: nil)
  }
  </code></pre>
  
  <p>Firebase Singleton class DataService:</p>
  
  <pre><code>import Foundation
  import Firebase
  
  let DB_BASE = Database().reference()
  
  class DataService {
  
  static let ds = DataService()
  
  private(set) var REF_BASE = DB_BASE
  private(set) var REF_PROMOS = DB_BASE.child("promos")
  private(set) var REF_NEGOCIOS = DB_BASE.child("negocios")
  private(set) var REF_USERS = DB_BASE.child("users")
  
  func createFirebaseDBUser(uid: String, userData: Dictionary&lt;String, String&gt;){
      REF_USERS.child(uid).updateChildValues(userData)
  }
  
  }
  </code></pre>