谁能解释我需要做的步骤?尝试在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))")
最佳答案
您不需要snapshot().value
上的()。将其设置为snapshot.value as? [String: AnyObject]
,将消除错误“无法调用非函数类型'DataSnapshot'的值”
基本上可以从字面上理解该错误。快照(类型为DataSnapshot)不是函数,因此您不能将其称为函数,即snapshot()
关于swift - 如何使用Firebase实时数据库在tableView中显示数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47839824/