i want to load data in array when i go in the view controller.When i print the array, it is empty but if i use a refresh and print again the array, he is loaded.It is the code :
var information = [String]()
override func viewDidLoad() {
super.viewDidLoad()
loadinformation()
print(information)
}
func loadinformation() {
let ref = Database.database().reference()
let uid = Auth.auth().currentUser?.uid
let prof = ref.child("users").child(uid!).child("interess")
prof.observeSingleEvent(of: .value,with: { (snapshot) in
if let dict = snapshot.value as? [String: Any] {
let name = dict["FullName"] as! String
self.information.append(name)
}
})
}