title: Copy one child's data into another with Firebase
body: <p>I have this function where I check whether child A has a child, and if not I want to copy child B into child A.</p>
  
  <p>Currently I'm trying to get a snapshot of B and write it to A. Can't get it work.</p>
  
  <p>I'm a beginner with Swift and Firebase and found similar questions but in other languages which I don't understand.</p>
  
  <p>My code:</p>
  
  <pre><code>    ref.child("Users").child("Friends").child(String(a)).observe(.value, with: { (snapshot) in
          if(snapshot.exists()){
              if(snapshot.hasChild(String(b))){
                //perform operation on node A
              } else {
                   //Here I want to copy DefaultFriends-&gt;x into Users-&gt;Friends-&gt;x
                  //perform operation on node A
           } else {
              //Here I want to copy entire DefaultFriends into Users-&gt;Friends
              //perform operation on node A
          }
      })
  </code></pre>
  
  <p>My database is structured:</p>
  
  <pre><code>    ----Users 
      ---------Friends
  
      //e.g put Child B here
  
      ----------------2
      -------------------Friend21
      -------------------Friend22
  
      ---DefaultFriends 
      -------------------1 //Child B
      ---------------------DefaultFriend11
      ---------------------DefaultFriend12
      -------------------2
      ---------------------DefaultFriend21
      ---------------------DefaultFriend22
      ---------------------DefaultFriend23
      ---------------------DefaultFriend24
  </code></pre>