I am reading data from Firebase Database in Swift, then want to use length in later in function, however I lost the assignment done in with: closure. AKA the two print(length!) print different values. How can I remember this assignment whether it be a workaround to closures in Swift or way to save save value with a Firebase call.
var length:Int? = 1
ref.child("Config").observeSingleEvent(of: .value, with: { (snapshot) in
let value = snapshot.value as? NSDictionary
length = (value?["AcademicBuildingsLength"] as? Int ?? 0)
print(length!)
})
print(length!)