0
 var usernameEntered = self.textField.text!
 var databaseReferenceQuery = DataService.ds.REF_USERS.queryOrderedByChild("username").queryEqualToValue(usernameEntered).observeSingleEventOfType(.Value, 
    withBlock: { (snapshot) in

        if ( snapshot.value is NSNull ) {

        } else {
            print(snapshot.key)
            print(snapshot.value.)
        }
    }, withCancelBlock: { (error) in
            // An error occurred
    })
}

This is what I've got.

My firebase database is set up like :

Users
    20394802938lsjfkjaweli (the uid)
         username: Bob
    0skjflakjlkwjf93j09
         username: Bobby

By running that query I'm searching through the usernames and checking to see if it equals what's entered into the text field.

When I do something like print(snap.value) I get "username: (whatever i put into the text field if it matches a username)

What I need is to be able to snag the user ID associated with that username.

Using snapshot.key provides me with "Users". How do I get one level below that?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Barkley
  • 6,063
  • 3
  • 18
  • 25

1 Answers1

0
 for child in snapshot.children {
  let key = child.key as String
  print("this key \(key)")

Takes the returned snapshot and sets the variable key to the child's key, which in this case in the UID,

Barkley
  • 6,063
  • 3
  • 18
  • 25