title: Iterate through nested snapshot children in Firebase using Swift
body: <p>I'm trying to loop through children in my Firebase Database to retrieve a nested key.</p>
  
  <p>My database is structured like this:</p>
  
  <pre><code>"Users" : {
   "Username" : {
    "Favorites" : {
      "Location" : {
        "Latitude" : 123,
        "LocationName" : "San Francisco",
        "Longitude" : 123
      },
      "Location2" : {
        "Latitude" : 123,
        "LocationName" : "London",
        "Longitude" : 123
      }
    }
   }
  }
  </code></pre>
  
  <p>I am trying to print out all of the "LocationName" keys, and am able to print one instance of this key, but not able to loop through and print all instances of this key. </p>
  
  <p>I'm not sure where in my for loop I'm going wrong?</p>
  
  <p>The code I'm working with is below. </p>
  
  <pre><code>    FIRApp.configure()
  
      let databaseRef = FIRDatabase.database().reference().child("Users").child("Username").child("Favorites")
  
  
      let databaseHandle = databaseRef.observe(.value, with: { (snapshot) in
          for item in snapshot.children {
  
              if let dbLocation = snapshot.childSnapshot(forPath: "LocationName") as? String {
  
                      print (dbLocation)
              }
  
              print(item)
  
          }
  
      })
  </code></pre>
  
  <p>I'm very new to Swift, and even newer to Firebase, so any help would be greatly appreciated!!</p>