如何在带有Firebase实时数据库的tableView中显示数据

时间:2017-12-15 21:02:54

标签: swift xcode firebase firebase-realtime-database

有人可以尝试解释我需要做的步骤吗?当我尝试在Xcode中定义数据库时,我遇到了很多错误。

dbRef.child("class").observeSingleEvent(of: .value, with: 
{ (snapshot) in

        let value = snapshot().value? as? [String: AnyObject]

        let description = value? ["desciption"] as? [Any]
        let owner = value? ["owner"] as? [Any]
        let participant = value? ["participant"] as? [Any]
        let time = value? ["time"] as? [Any]

        print("description: \(String(describing: description))")
        print("owner: \(String(describing: owner))")
        print("participant: \(String(describing: participant))")
        print("time: \(String(describing: time))")

1 个答案:

答案 0 :(得分:0)

您不需要snapshot().value上的()。设为snapshot.value as? [String: AnyObject]即可删除错误"无法调用非功能类型的值' DataSnapshot'"

基本上可以从字面上理解错误。快照(类型为DataSnapshot)不是函数,因此您无法将其称为函数,即snapshot()