title: Query users by name or email address using Firebase (Swift)
body: <p>I'm quite new to <strong>Firebase</strong> and <strong>Swift</strong> and I'm having some trouble when it comes to querying.
  So there are basically two things I'd like to do:</p>
  
  <ol>
  <li>Query my users and <strong>find only those that contain a certain String</strong> in their name (or email address) and add them to an array.</li>
  <li>Get all of my users and add them to an array.</li>
  </ol>
  
  <p>The relevant part of my data for this question looks like this:
  <img src="https://i.stack.imgur.com/oP8G6.png" alt="enter image description here"></p>
  
  <p>As you can see, I'm using the simplelogin of Firebase (later I'd like too add Facebook login) and I'm storing my users by their uid.</p>
  
  <p>A part of my rules file looks like this:</p>
  
  <pre><code>"registered_users": {
      ".read": true,
      ".write": true,
      ".indexOn": ["name"]
   }
  </code></pre>
  
  <p>So everybody should have read and write access to this part of my data.</p>
  
  <p>I also read the "Retrieving Data" part of the Firebase iOS Guide on their website and according to that guide, my code on getting all the users names and email addresses should work, at least I think so. But it doesn't. Here is my code:</p>
  
  <pre><code>func getUsersFromFirebase() {
          let registeredUserRef = firebaseRef.childByAppendingPath("registered_users")
          registeredUserRef.queryOrderedByChild("name").observeSingleEventOfType(.Value, withBlock: { snapshot in
              if let email = snapshot.value["email"] as? String {
                  println("\(snapshot.key) has Email: \(email)")
              }
              if let name = snapshot.value["name"] as? String {
                  println("\(snapshot.key) has Name: \(name)")
              }
          })
      }
  </code></pre>
  
  <p>I noticed, that in the firebase guide, they always used the type ChildAdded and not Value, but for me Value makes more sense. The output with Value is nothing and the output with ChildAdded is only one user, namely the one that is logged in right now.</p>
  
  <p>So my questions are:</p>
  
  <ol>
  <li>Can I do this query with my current data structure or do I have to get rid of storying the users by their uid?</li>
  <li>If yes, how would I have to change my code, to make it work?</li>
  <li>If no, what would be the best way to store my users and make querying them by name possible?</li>
  <li>How can I query for e.g. "muster" and get only the user simplelogin:1 (Max Mustermann)?</li>
  </ol>
  
  <p>I hope my description is detailed enough. Thx in advance for your help.</p>
  
  <p><strong>Supplement</strong>:</p>
  
  <p>The weird thing is, that the "Retrieving Data" guide says, that querying and sorting the following data by height is possible.</p>
  
  <p>Data:</p>
  
  <p><img src="https://i.stack.imgur.com/7ECuX.png" alt="enter image description here"></p>
  
  <p>Querying code:
  <img src="https://i.stack.imgur.com/6rcxX.png" alt="enter image description here"></p>
  
  <p>And isn't that exactly the same that I intent to do?</p>