ios - 如何在不从 firebase For ios 获取值的情况下读取父节点名称

标签 ios swift firebase

我想使用 swift 读取 restaurant names Burger King, Eating Point

这怎么可能,谁能帮帮我,这是因为我的期末项目需要在 1 周内提交,我对这个失去了希望

enter image description here

 ref = Database.database().reference()

    ref?.child("Restaurants").observe(.childAdded, with: { (snapshot) in
        let rest = snapshot.value as? String
        if let actualPost = rest {


            self.restList.append(actualPost)

            print("list of rest ", self.restList)


            self.restTableView.reloadData()
        }
    })

最佳答案

只需使用以下代码获取父节点名称。

 ref = Database.database().reference()

 ref?.child("Restaurants").observe(.childAdded, with: { (snapshot) in
    let rest = snapshot.value as? String
// snapshot.key is give you parent node name
        print(snapshot.key)
    }
})

关于ios - 如何在不从 firebase For ios 获取值的情况下读取父节点名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50207287/

相关文章:

java - 适配器中的 Android RecyclerView 显示问题

ios - 无法从包中加载 Info.plist

ios - 使用 iOS TabBar 作为任务栏

ios - iOS 8.1.3 上未安装企业应用程序部署

ios - Swift 中使用的 Objective-C 框架 - 方法错误的不明确使用

ios - DidSelectRowAt 不会返回所需的项目

ios - GameCenter 与 SpriteKit 集成

javascript - React Firebase 时间戳用法

ios - 响应 UNUserNotificationAction

ios - 如何知道 FirebaseApp.configure() 何时完成?