I am trying to retrieve data from Firebase and store that data outside of the closure that retrieves that data.
var stringNames = [String] ()
ref?.observeEventType(.Value, withBlock: { snapshot in
var newNames: [String] = []
for item in snapshot.children {
if let item = item as? FIRDataSnapshot {
let postDict = item.value as! [String: String]
newNames.append(postDict["name"]!)
}
}
stringNames = newNames
})
print(stringNames)
stringNames comes back empty, but when I print from inside the closure it has the correct data. Any help would be much appreciated, thank you!