0

i try to iterate over a list of ids to get values. While iterating i want to store it in another list. After iterating i try to start next method with the new List. Unfortunately the size is always 0 but there are values of curse. If i print it out within my loop its the right size but afterwards not. Here is my Code:

 func getUsersForFences(geofenceObject: [GeofenceObject]){
    for fence in geofenceObject{
    let ref = Database.database().reference().child("UserInFences").child(fence.fenceName!)
    ref.observeSingleEvent(of: .value, with: { (snapshot) in
        if snapshot.childrenCount > 0{
            for users in snapshot.children.allObjects as! [DataSnapshot]{
                let userItem = users.value as? [String: AnyObject]
                let userid = users.key as! String
                let timestamp = userItem?["timestamp"] as! Int
                let timestampValidation = userItem?["timestampValidation"] as! Int


                if fence.timestamp! <= timestamp && fence.timestampValidation! <= timestampValidation && timestamp <= fence.timestampValidation! {
                    let userObjecti = UserFenceObject(timestamp: timestamp, timestampValidation: timestampValidation, userId: userid)
                    self.userObjects.append(userObjecti)


                }else if fence.timestamp! >= timestamp && fence.timestampValidation! >= timestampValidation && fence.timestamp! <= timestampValidation {
                    let userObject = UserFenceObject(timestamp: timestamp, timestampValidation: timestampValidation, userId: userid)
                    self.userObjects.append(userObject)
                }
            }

        }
    });
    }

// Here its always 0
    self.getUsersInterest( userObject: userObjects)
}
Dominik
  • 419
  • 2
  • 6
  • 16

0 Answers0