从数据库中检索数据并显示? iOS

时间:2018-08-15 08:17:09

标签: ios swift database firebase cocoapods

我是Firebase和Pod中的新手。我在从数据库检索数据时遇到问题。我认为Firebase具有的库做错了。我的应用程序运行良好,但未在控制台中显示结果,有人可以解释为什么无法从我的数据库中获取信息。同样,来自不同服务器的任何资源也会有很大帮助。这就是我所拥有的。

This is my code

This is the last one image (click)

PS:还有其他信息让我知道,谢谢!!

2 个答案:

答案 0 :(得分:1)

首先,您应该将观察者的DateType更改为.value,因为.childAdded仅在添加子项时执行。

第二,您应该遍历所有“ bestBuyLocations?”并获取经纬度。

请参见以下示例:

let databaseRef = Database.database().reference().child("bestBuy")
databaseRef.observe(.value) { snapshot in
    if let snapShotValue = snapshot.value as? NSDictionary {
        for location in snapShotValue {

            if let locationValues = location.value as? [String: Any] {
                if let lon = locationValues["lon"] as? NSString {
                    print(lon)
                }

                if let lat = locationValues["lat"] as? NSString {
                    print(lat)
                }
            }

        }
    }
}

答案 1 :(得分:-1)

根据您附加的图片,它是 firestore 而非实时数据库。您添加的代码用于实时数据库。请查看 Firestore 文档以检索数据。

相关问题