title: Firebase check for existing user in swift
body: <p>I have VC where by I am creating a new user and adding to firebase. The user inserts no problem into the database but I am having trouble checking if a user with the same name already exists. I have tried using various query statements within firebase but not getting any joy. Does anyone know how I can modify my code to accomplish this? here it is :-</p>
  
  <pre><code> @IBAction func submitUsername(sender: AnyObject) {
  
      if let user = usernameTxtField.text where user != "" {
  
         let username = DataService.ds.REF_USERS.childByAppendingPath("username")
  
         username.observeSingleEventOfType(.Value, withBlock: {  snap in
  
              if let usernameDoesNotExist = snap.value as? NSNull {
                let currentUser = DataService.ds.REF_USER_CURRENT.childByAppendingPath("username")
                self.usernameTxtField.text = user
                currentUser.setValue(user)
              }
         })
  
         dismissViewControllerAnimated(true, completion: nil)
  
      } else {
          showAlert("Username Needed", msg: "please choose a username")
      } 
  }
  </code></pre>
  
  <p>and the firebase data structure</p>
  
  <pre><code>"users" : {
      "000591b6-ba88-4670-9cb7-edd79c273eab" : {
        "newuser" : "added to FB",
        "provider" : "password"
      },
      "05551c90-27fe-4969-b45d-279a72583857" : {
        "newuser" : "added to FB",
        "provider" : "password"
      },
      "0bbff1b0-681a-4fef-adc0-c4779a4b2100" : {
        "provider" : "password",
        "testing" : "emailtest",
        "username" : "richy446"
      },
      "12f35e7a-2430-49b3-a287-f7b1daf6a121" : {
        "newuser" : "added to FB",
        "provider" : "password",
        "username" : "richy445"
      },
      "15a45560-cc81-4c2d-bb59-b8ce6b125d68" : {
        "provider" : "password",
        "testing" : "emailtest",
        "username" : "richy445"
      },
      "1c135936-6dd0-4189-bcd7-e8036e9736f9" : {
        "newuser" : "added to FB",
        "provider" : "password"
      },
      "21591e29-f083-452c-b74f-cc567cecb183" : {
        "newuser" : "added to FB",
        "provider" : "password"
      },
      "8b385aa7-0e80-426b-a385-5b3317c894d0" : {
        "newuser" : "added to FB",
        "provider" : "password",
        "username" : "richy445"
      }
  }
  </code></pre>