Is there any reason why this function is returning an empty array? I've run it through the debugger and the for loop is working and is appending users to the newUsers array but by the time it finishes and goes to return the value, its empty.
func fetchUsers(ref:FIRDatabaseReference) -> [User] {
var newUsers = [User]()
ref.observeEventType(.Value, withBlock: {snapshot in
for user in snapshot.children {
let users = User(snapshot: user as! FIRDataSnapshot)
newUsers.append(users)
}
})
print("closure exited. There are \(newUsers.count) Users in newUsers")
return newUsers
}