尝试创建快照以保存到Swift Firebase中的tableviewcell

时间:2018-08-08 19:24:05

标签: ios swift firebase firebase-realtime-database

我有一个名为story的自定义类,当按下创建帖子的按钮时,我能够创建该帖子的快照,但是我试图将配置文件图像的URL和全名保存到firebase中的相​​同位置并添加它创建帖子后调用的快照。但是当我的代码运行时,我得到一个错误

这是代码

class Story
{
    var text: String = ""
    var fullname: String = ""
    var profimage: String = ""
    let ref: DatabaseReference!
    var rub: StorageReference!
    init(text: String) {
        self.text = text

        ref = Database.database().reference().child("People").child("HomeFeed").child("Posts").childByAutoId()

    }
    init(fullname:String){

        self.fullname = fullname


        ref = Database.database().reference().child("People").child("HomeFeed").child("Posts").childByAutoId()


    }

    init(profimage: String) {

        self.profimage = profimage


        ref = Database.database().reference().child("People").child("HomeFeed").child("Posts").childByAutoId()

    }


    init(snapshot: DataSnapshot)
    {
       ref = snapshot.ref
        if let value = snapshot.value as? [String : Any] {
            text = value["Post"] as! String

            fullname = value["Full Name"] as! String


            profimage = value["Profimageurl"] as! String


        }else{
            print("no stories here")
        }
    }

    func imageurl(url: String) {

        ref.updateChildValues(["Profimageurl": url])

    }

        func save() {
       ref.setValue(toDictionary())

    }

    func toDictionary() -> [String : Any]
    {
        return [
            "Post" : text,

            "Full name" : fullname,

            "Profimageurl" : profimage
        ]
    }
}

0 个答案:

没有答案