I make a call to Firebase database to update the variable cars. My database has children. When I print cars in the call's loop I get all my car's name but out of it it an empty string array. For example, when I print cars from viewDidLoad out of the observe method, it is [ ].
let ref = Database.database().reference()
var cars: [String] = []
override func viewDidLoad() {
super.viewDidLoad()
ref.observeSingleEvent(of: .value, with: { (snapshot) in
let value = snapshot.value as? NSDictionary
for child in value! {
self.cars.append(child.key as! String)
}
}) { (error) in
print(error.localizedDescription)
}