askaale askaale -5 years ago 227
Swift Question

Swift/Firebase copy path

Basically I am struggling with copying paths to other destinations. I have a directory with root/users/id/info, like this:


However, what I want to accomplish, is to move the path with the ID (that contains all the information about andreas, to another path
so it looks like this:
, but I can't seem to find a way to do so. Any ideas?

Thanks in advance..

Here is the code I currently have:

ref.child("Users").child(uid).observeEventType(FIRDataEventType.ChildAdded) { (snap:FIRDataSnapshot) in
var pathway = snap
self.ref.child("HighestRanking").child(uid)..setValue([pathway], withCompletionBlock: { (error, ref) in
if error != nil {
print("An error occured.")
} else {

//An error occurs.. Tried several other methods as well..

Answer Source

What you might be looking for is something like the following:

ref.child("Users").child(uid).observeEventType(FIRDataEventType.Value, withBlock: { (snapshot) in
  if let data = snapshot.value as! [String : AnyObject] {

Observe that since you want to "copy" the data when a UIButton is triggered you should be using FIRDataEventType.Value instead of FIRDataEventType.ChildAdded.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download