Я пытаюсь отобразить словарь [String: [Double]] в UITableView, но я получаю неожиданное поведение, когда удваивается появляется с различными форматами от оригинала.Вот мой основной код:
var resdict = ["Joao":[55.5,43.8,88.5],"Carlos":[65.5,45.8,58.5],"Eduardo":[45.5,75.8,53.5]]
struct Objects {
var sectionName : String
var sectionObjects : [Double]
}
var objectArray = [Objects]()
//table
@IBOutlet weak var resultsTable: UITableView!
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return objectArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath as IndexPath) as UITableViewCell
let name = objectArray[indexPath.row].sectionName
let notas = objectArray[indexPath.row].sectionObjects
cell.textLabel?.text = "\(indexPath.row + 1) \(name) -> \(notas)"
return cell
}
И при viewDidLoad:
for (key, value) in resdict {
print("\(key) -> \(value)")
objectArray.append(Objects(sectionName: key, sectionObjects: value))
}
Результаты:
1 Eduardo -> [45.5, 75.799999999999997, 53.5]
2 Joao -> [55.5, 43.799999999999997, 88.5]
3 Carlos -> [65.5, 45.799999999999997, 58.5]
Я знаю, что мне следует применить что-то вроде String (формат: "% .2f", ...) но где и как?