I have a method that takes in an array and inside that method I want to append some objects to that array. Since Swifts parameters to functions are immutable I'm unable to do so. It is vital that I maintain the same reference to that array since that array is going to be used in a table view to display data. My code is as follows:
class func loadData(tableView: UITableView, results: [LocationInfo]){
print("\n Data fetch started \n")
let root = FIRDatabase.database().reference()
let locationSummary = root.child("LocSummary")
locationSummary.observeSingleEvent(of: .value,with: { (snapshot) in
for item in snapshot.children{
let locationInfo = LocationInfo(snapshot: item as! FIRDataSnapshot)
results.append(locationInfo) // ERROR IS WITH THIS
}
DispatchQueue.main.async {
print("\n data fetch completed \n ")
tableView.reloadData()
print("After on completion method \(results.count)")
}
})
}
How can I append data to this array while maintaining the same reference.