迅速将所有内容从geoFire键追加到集合视图

时间:2018-11-12 01:30:52

标签: swift firebase firebase-realtime-database geofire

我正在尝试在circleQuery内附加所有帖子,目前我正在从控制台中的每个键中打印出所有postId。但是没有任何内容被附加到集合视图中。

var posts = [Post]()
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    let userLocation: CLLocation = locations[0] as CLLocation
    let currentUserLocation = userLocation

    let circleQuery = geoFire?.query(at: currentUserLocation, withRadius: 100.0)

    _ = circleQuery?.observe(.keyEntered, with: { (key, location) in
        print(key)

        var post = key

        self.posts.append(post)
        self.posts.sort(by: { (post1, post2) -> Bool in
            return post1.creationDate.compare(post2.creationDate) == .orderedDescending
        })
        self.collectionView?.reloadData()

        self.locationManager.stopUpdatingLocation()
    })
}

Firebase post node

0 个答案:

没有答案