title: Firebase-database - How to fetch child values from multiple children nodes and store in Swift Dictionary
body: <p>My database structure is as follows: </p>
  
  <pre><code>"routines": {
    "users unique identifier": {
      "routine unique identifier": {
        "routine_name": "routine name",
        "routine_create_date": "routine created date",
        "exercises": {
          "exercise name": {
            "Sets": "number of sets"
          }
        }
      }
    }
  }
  </code></pre>
  
  <p>When retrieving data I am wanting to store each <code>routine</code> as an object to load in to a <code>UITableView</code>. The routine structure I am using is: </p>
  
  <pre><code>struct Routine {
    var routineName: String!
    var routineExercisesAndSets: [String:Int]!
  }
  </code></pre>
  
  <p>How can I retrieve the values from this so that for each <code>Routine</code> model I can have  <code>Routine(routineName: "Legs", routineExercisesAndSets: ["Squats":4,"Lunges":4,"Calf Raises":4])</code> where the dictionary of exercises is the <code>exercise name</code>:<code>number of sets</code>.</p>
  
  <p>I am currently using a different structure and can nearly get the result I want through:</p>
  
  <pre><code>let ref = FIRDatabase.database().reference().child("routines").child(userId)
  var routineTemp = Routine()
  ref.observe(.childAdded, with: { (snapshot) in  
      if let dictionary = snapshot.value as? [String : AnyObject] {
          routineTemp.routineName = dictionary["routineName"] as! String
          let enumerator = snapshot.childSnapshot(forPath: "exercises").children
          var exercisesAndSets = [String:Int]()
          while let item = enumerator.nextObject() as? FIRDataSnapshot {
              exercisesAndSets[item.key] = item.value! as? Int
          }
          routineTemp.routineExercisesAndSets = exercisesAndSets
          print(routineTemp)           
      }    
  } , withCancel: nil)
  </code></pre>