在Swift中将一个孩子从一个节点更改为另一个节点用于Firebase

时间:2017-10-15 22:51:16

标签: swift firebase firebase-realtime-database

这是我的数据库结构:

self.ref.child("users").child(user1).child(nodeA).child(nodeToBeMoved).observe(.value, with: { (snapshot) in
            let value = snapshot.valueInExportFormat() as AnyObject
            self.ref.child(users).child(user1).child(nodeA).child(nodeToBeMoved).removeValue()
            self.ref.child(users).child(user2).child(nodeB).child(nodeToBeMoved).child(content).setValue(value["content"] as Any)
            self.ref.child(users).child(user2).child(nodeB).child(nodeToBeMoved).child(date).setValue(value["date"] as Any)



        }) { (error) in
            print(error.localizedDescription)
        }

我希望移动" nodeToBeMoved"从节点A到节点B,我试图将content1和date1放入变量" value"然后,删除" nodeToBeMoved",然后将变量添加到节点B.但由于某种原因,我的应用程序崩溃了。这是我的代码:

from tkinter import *

# ==================================================Settings=======================================================
root = Tk()
root.title("Video Youtube Downloader") # set up the title and size.
root.configure(background='black') # set up background.
root.minsize(800, 500)
root.maxsize(800, 500)
# ==================================================Frames=======================================================
top = Frame(root, width=800, height=50,  bg='yellow').pack(side=TOP)
bottom = Frame(root, width=800, height=50,  bg='red').pack(side=BOTTOM)
left = Frame(root,  width=550, height=450, bg='black').pack(side=LEFT)
right = Frame(root, width=250, height=450, bg='blue').pack(side=RIGHT)



# ==================================================Buttons=======================================================
btn_clear_url = Button(right, text="Clear Url", font=('arial', 10, 'bold')).grid(row=1, columns=1)

我相信我的变量类型有问题。有人可以帮我解决这个问题吗?这也是我的方法,但如果你知道更好的方法,请随意说出来。

1 个答案:

答案 0 :(得分:0)

试试这个`

self.ref.child("users").child(user1).child(nodeA).child(nodeToBeMoved).observe(.value, with: { (snapshot) in
        let value = snapshot.value as NSdictionnary
         if let actualvalue = value {
         self.ref.child(users).child(user1).child(nodeA).child(nodeToBeMoved).removeValue()
        self.ref.child(users).child(user2).child(nodeB).child(nodeToBeMoved).child(content).setValue(actualvalue["content"] as Any)
        self.ref.child(users).child(user2).child(nodeB).child(nodeToBeMoved).child(date).setValue(actualvalue["date"] as Any)

        }




    }) { (error) in
        print(error.localizedDescription)
    }