【发布时间】:2021-08-13 10:23:56
【问题描述】:
我正在尝试使用我的 firebase 实时数据库中的数据创建一个列表,但我在列表行上收到此错误:
错误:
Type 'Void' cannot conform to 'View'
我的代码: struct ActiveGoalsView: 查看 {
@State var goals = ["finish this project"]
@State var ref = Database.database().reference()
var body: some View {
NavigationView {
List {
ref.child("users").child(Auth.auth().currentUser?.uid ?? "noid").child("goals").observeSingleEvent(of: .value) { snapshot in
for snap in snapshot.children {
Text(snap.child("title").value)
}
}
}.navigationBarHidden(true)
}
}
}
struct ActiveGoalsView_Previews: PreviewProvider {
static var previews: some View {
ActiveGoalsView()
}
}
【问题讨论】:
-
改用
ForEach,在body之外做异步工作
标签: ios swift firebase swiftui