Please help me with filling table view cells with data from a dictionary. For instance, I have cell like so:
and for filling it with data I\'ve started with
Using only one array is better for tableView data instead of using dictionary or more arrays. To do this, you can create a struct to wrap all data a cell needs.
struct Currency {
let currency: String
let rate: Rate
}
You can turn dictionary to Currency array or assign your data to Currency at first.
var currencies = [Currency]()
for (key, value) in currencies! {
let currency = Currency(currency: key, rate: value)
currencies.append(currency)
}
Then use this array to cell.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CurrencyCell", for: indexPath) as! CurrencyCell
let currency = currencies[indexPath.row]
//assign data to cell
return cell
}