Getting all the users same child in Firebase (Swift)
<p>I am currently building an app in Firebase and I want to get all the users pineapple rate.</p>

<p>This is the tree:</p>

<pre><code>user1: uid1 {
  fruits: {
    apple: 3
    pineapple: 5
  }
}

user2: uid2 {
  fruits: {
    apple: 4
    pineapple: 2
  }
}
</code></pre>

<p>I tried this code:</p>

<pre><code>var ref = FIRDatabase.database().reference()
ref.queryOrderedByChild("fruits")
            .observeSingleEventOfType(.Value, withBlock: { (snapshot) in
                if ( snapshot.value is NSNull ) {
                    print("not found")
                } else {
                    for child in snapshot.children {
                        let rate = child.value["pineapple"] as! String
                        print(rate)
                    }
                }
            })
</code></pre>

<p>But it gives me an error of unwrapping Nil.</p>

<p>Picture of the structre:</p>

<p><a href="https://i.stack.imgur.com/GjMM2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GjMM2.png" alt="enter image description here"></a></p>