图片中所有值的自定义类USER
导入基础
导入 SwiftUI
导入 Firebase
导入 CodableFirebase
//知道用户ID,用Firebasedecoder清理漂亮的结果
func cleanResultWithCodebableFirebase(){
ref.child("3oleg").observeSingleEvent(of: .value, with: { snapshot in
guard let value = snapshot.value else { return }
do {
let user = try FirebaseDecoder().decode(User.self, from: value)
print(user.getUser_id())
} catch let error {
print(error)
}
})
}
不知道 userID 的脏结果
func customwithdirtylists(){
让查询 = ref.queryOrdered(byChild: Strings.field_username).queryEqual(toValue: "uiiii")
query.observeSingleEvent(
of: .value, with: { (snapshot) -> Void in
for child in snapshot.children {
let childSnapshot = snapshot.childSnapshot(forPath: (child as AnyObject).key)
for grandchild in childSnapshot.children{
let grandchildSnapshot = childSnapshot.childSnapshot(forPath: (grandchild as AnyObject).key)
//possible from here to get the key and values of each element of the custom class
}
}
})
}
这是我在两种情况下使用的代码,直接请求或订购时。在 firebase decode 的帮助下直接看不到列表。通过循环重建自定义类的丑陋方式。我相信有更优雅的方法可以做到这一点,特别是当我只需要删除直接结果的一个值以获得干净的结果时