func queryAll() -> [(String, String, String)] {
do {
let sql = try DB?.prepare("SELECT city, zip , temp FROM weather")
var arr : [(city : String, zip : String, temp : String)] = []
for row in sql! {
arr += [(city: row[0] as! String, zip: row[1] as! String, temp: row[2] as! String)]
}
return arr;
}
catch {
print("\(error)")
}
return [("","","")]
}
Grabbing all the rows, and returning them as a tuple for later use. I've read the docs but I cannot think of a more efficient way to return all the rows to a TableView
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell : CustomTableViewController = self.tableView.dequeueReusableCell(withIdentifier: "Cell")! as! CustomTableViewController
let DB : WeatherDataStorage = WeatherDataStorage()
var arr = [(city : String, zip : String, temp : String)]()
arr = DB.queryAll()
cell.cityLabel.text = arr[i].city
cell.zipLabel.text = arr[i].zip
cell.temperatureLabel.text = arr[i].temp
i += 1
return cell
}
EDIT: GIST
let cell : CustomTableViewController
because a cell cannot be a view controller. \$\endgroup\$let cell : CustomTableViewController
makes no sense. Please post your actual working code. – The definitions ofDB
andWeatherDataStorage
would also be relevant. \$\endgroup\$let cell: CustomTableViewController...
you can declare it aslet cell = self.tableView...
\$\endgroup\$DB
asdb
as per Swift's API Design Guidelines. Or in this case, something likedataStore
. \$\endgroup\$