按键检索Firebase对象

时间:2016-05-26 18:53:04

标签: swift uitableview firebase geofire

我正在使用Geofire存储物品及其位置。

为了检索特定区域内的项目,我使用Geofire的地理查询:

 var queryHandle = query.observeEventType(.KeyEntered, withBlock: {(key: String!, location: CLLocation!) in
  println("Key '\(key)' entered the search area and is at location '\(location)'")
 })

正如预期的那样,结果是指定区域中的键 - 我的问题是:如何获取实际对象以便我可以访问它拥有的其余属性?

我正在做所有这些作为UITableView的一部分,因为我想在表格中呈现我附近的对象(稍后在地图上)

使用geofire填充UITableView的任何最佳实践也将受到赞赏。

谢谢!

1 个答案:

答案 0 :(得分:0)

您只需创建一个值单个事件并读取该值即可。 Firebase快速而有效,可以读取它,这对于UITableViews和UICollectionViews都可以正常工作。


    //ref is the reference to your object's parent path, and key is the value you received with the geofire query
    ref.childByAppendingPath(key).observeSingleEventOfType(.Value, withBlock: {       
       (snapshot:FDataSnapshot!) in

        //The snapshot has the data of your actual object        

    })
相关问题