我有一个GeoFire查询,它只在方法keys
被调用两次后用适当的getLocalUsers
填充我的数组。如何才能通过1次呼叫才能实现此目的?这是我的代码......
@IBAction func getKeys(sender: AnyObject)
{
var allKeys = [String]()
let geofireRef = self.ref.child("UserLocations")
let geoFire = GeoFire(firebaseRef: geofireRef)
let circleQuery = geoFire.queryAtLocation(self.location, withRadius: 200.6)
circleQuery.observeEventType(.KeyEntered, withBlock: { (key: String!, location: CLLocation!) in
var users = [String]()
allKeys.append(key)
for keys in allKeys
{
let user = keys
users.append(user)
}
self.localUsers = users
self.getLocalUsers()
})
self.getLocalUsers()
}
答案 0 :(得分:0)
我并不认为这是Firebase问题,但不确定。我认为最重要的是在keys
,allKeys
的方法中创建一个数组,这样我就可以循环并正确地说出我的公共数组。以下是我如何使用它。 @FrankVanPuffelen请评论......
@IBAction getKeys()
{
var allKeys = [String]()
let geofireRef = self.ref.child("UserLocations")
geofireRef.keepSynced(true)
let geoFire = GeoFire(firebaseRef: geofireRef)
let circleQuery = geoFire.queryAtLocation(self.location, withRadius: 200.6)
circleQuery.observeEventType(.KeyEntered, withBlock: { (key: String!, location: CLLocation!) in
var users = [String]()
users.append(key)
for keys in users
{
let user = keys
allKeys.append(user)
}
self.localUsers = allKeys
self.friendsNearMeACTN()
})
}