ios - 无法从 firebase 数据库获取 key

标签 ios firebase swift2 firebase-realtime-database

我在学生程序员生涯中思考的时间最长。我想知道

我使用 autoChildId 添加了 key 。

  1. 如何从 firebase 数据库 swift 2 获取 key ?我知道如何使用 .getKeys() 从 Android 获取

  2. 我最好的 friend Google 教我使用 allKeys。然而,我的友谊现在正处于绝望的边缘,因为我收到以下消息,我们与 .allKeys 的关系将永远失败(见下图)。哈什……

Evidence of our relationship status right now

  1. 我需要这个来将 Firebase 数据库中的数据显示到我的 TableView 中,因为我相信这是一个空表的问题,就像我对我的项目的心意一样。没有心。

这是我的 firebase 数据库的样子:

My firebase database

这是我的代码:

func findPlaceToEat(){
    print("inside findPlaceToEat()")

    print("Plan price level")
    print(planPriceLevel)
    print("End of price level")

    ref = FIRDatabase.database().reference()

    ref.child("places_detail").child("price_level").child(planPriceLevel).observeEventType(.ChildAdded, withBlock:{
        (snapshot) in

        if let dictionary = snapshot.value?.allKeys! as? [String: AnyObject]{
            let PlaceObj = placeObj(place_name: dictionary["place_name"] as! String, place_type: dictionary["place_type"] as! String, price_range: dictionary["price_range"] as! String, vegan_type:dictionary["vegan_type"] as! String , website: dictionary["website"] as! String)
            print("Whatever")

            print(PlaceObj);
            //self.tableView.reloadData()

        }
        }, withCancelBlock: nil)
}

最佳答案

从快照中获取 key

snapshot.key

关于ios - 无法从 firebase 数据库获取 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42227064/

相关文章:

ios - 如何检查当前的 RestKit 版本

ios - 如何在 Swift 3 中使用 SDWebImage 在 UITableViewCell 中正确设置 ImageView

ios - Swift & Firebase - isPersistenceEnabled 后不同步

ios - UITableView 中的自定义单元格(iOS 9)

ios - 如何在发布前查看iOS App Store URL?

ios - 响应 child 和 parent 的触摸事件

swift - 将数据从 PageVC 发送到 Firebase

ios - Firebase Swift - 如何创建一个 child 并将其 id 添加到另一个 ref 属性?

ios - 如何根据 CollectionViewCell 的项目更改 UIPageControl 的当前位置

ios - 快速添加子项目