title: Retrieving Data from Firebase under ChildByAutoId and adding to array - Xcode - Swift
body: <p>Here is my Database from Firebase:</p>
  
  <p><a href="https://i.stack.imgur.com/MDxGZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MDxGZ.png" alt="enter image description here"></a></p>
  
  <p>Im trying to get the data for all purchases and quantities under "Tgb9MyxTfdTRd9tQhInsjNRXoPL2" and add to an array.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    func fetchPurchase(withUID uid: String, completion: @escaping (Purchase) -&gt; ()) {
          Database.database().reference().child("purchases").child(uid).observeSingleEvent(of: .value, with: { (snapshot) in
  
  
          guard let dict = snapshot.value as? [String: Any] else { return }
              print("dict--&gt;", dict)
          let purchase = Purchase(uid: uid, dictionary: dict)
              print("purchase--&gt;", purchase)
          completion(purchase)
      }) { (err) in
          print("Failed to fetch purchase from database:", err)
      }
  }
  </code></pre>
  
  <p>This is the print out for <code>print("dict--&gt;", dict)</code>:</p>
  
  <pre><code>dict--&gt; ["-LzjaFBgD3ATl7e8uR2-": {
  purchase = "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzk4OTUzMjEyODM=";
  quantity = 1;
  }, "-LzjaFBiAmrj4m3ZS8m4": {
  purchase = "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzk4OTUzMDk2OTk=";
  quantity = 2;
  }]
  </code></pre>
  
  <p>This is the print out for <code>print("purchase--&gt;", purchase)</code>:</p>
  
  <pre><code> purchase--&gt; Purchase(uid: "Tgb9MyxTfdTRd9tQhInsjNRXoPL2", purchases: "", quantities: "")
  </code></pre>
  
  <p>The value dict holds the data I need, but I cant get past that to put the data into an array to display it?</p>
  
  <p>How can I get the purchase and quantity data into their own arrays?</p>
  
  <p>Please help!</p>