I tried adding padding to the columnHeader, but still received a
Swift/ContiguousArrayBuffer.swift:580: Fatal error: Index out of range
Error message…
// for columnLabel in columnLabels {
for i in 0 ..< dataSource.numberOfColumns {
let columnLabel = dataSource.label(forColumn: i)
let columnHeader = " \(columnLabel) |"
// bronze challenge, trying to pad the column headers
let paddingNeeded = columnWidths[i] - columnLabel.count
let padding = repeatElement(" ", count: paddingNeeded).joined(separator: "")
headerRow += " \(padding)\(columnHeader)"
columnWidths.append(columnLabel.count)
}
print(headerRow)
What did I do wrong?
The too-easy solution would be to add spaces around the “Age” column header, but I’m sure that’s not what the Challenge is looking for.
Also, I changed the separator for the data rows from “” to “stuff”, and I noticed that the separators did not appear around the Age values. Why didn’t they appear?
Table: Department (Engineering)
| Employee Name | Age | Years of Experience |
| stuff stuff stuff stuff stuff stuff stuff stuff stuff Eva | 30 | stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff 6 |
| stuff stuff stuff stuff stuff stuff stuff Saleh | 40 | stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff 28 |
| stuff stuff stuff stuff stuff stuff stuff stuff Amit | 50 | stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff 20 |