title: swift 3, iOS Firebase Database sometimes crash when writing data (set value)
body: <p>sometimes my app is crashing when I´m trying to set a value in a Firebase Database. Here´s my code:</p>
  
  <pre><code>var databaseRef = FIRDatabaseReference()
  
  func sendregistrationtoken() {
      print("tokenRefreshNotification")
  
      guard let contents = FIRInstanceID.instanceID().token()
          else {
              return
      }
  
      if let userusername: String = Keychain().accessibility(.afterFirstUnlock)["userusername"] {
          if let refreshedToken = FIRInstanceID.instanceID().token(){
              let defaults = UserDefaults.standard
              defaults.set(refreshedToken, forKey: "userregistrationtoken")
              let userid = userusername.replacingOccurrences(of: ".", with: "%2E")
              let post : [String:AnyObject] = ["token" : refreshedToken as AnyObject]
  
              databaseRef = FIRDatabase.database().reference()
              databaseRef.child("Users").child(userid.uppercased()).setValue(post){ (error, ref) -&gt; Void in
                  print(error ?? "noerror")
              }
  
              connectToFcm()
          }
      }
  
  }
  
  func connectToFcm() {
      print("connectToFcm")
      FIRMessaging.messaging().connect { (error) in
          if (error != nil) {
              print("Unable to connect with FCM. \(error)")
          } else {
              print("Connected to FCM.")
          }
      }
  }
  </code></pre>
  
  <p>I call sendregistrationtoken() in my viewdidload of may main view controller. Here´s what my crash report says:</p>
  
  <pre><code>+[FValidation validateFrom:validPathString]
  </code></pre>
  
  <p>I´m using XCode 8 / Swift 3 and the latest Firebase SDK. Many Thanks
  Stephan</p>