allRowsAlignment value confusion (raise an assertion when it shouldn't)
Closed this issue · 2 comments
I'm trying to follow the example for creating a PDFTable
so
I'm creating the table with the needed size
var table = PDFTable(rows: 3, columns: 4)
setting the content
table.content = data //an array matching the size provided earlier
Setting the alignments
table.rows.allRowsAlignment = [.left, .left, .left, .right]
An assertion is raised and in prod. an exception with a crash
it says "Can not access more rows than available"
now my expectation from the last line is that I'm getting the rows and I'm setting the alignment to each cell in that each row
so the count of the alignments array should match the columns count
in my case this correct the alignments array matches the columns count (still an error)
I looked at the code behind that setter (which might be better as a function since it doesn't have a getter) and it says newValue.count <= rows.count
which make me feel that my understanding might be wrong because it's checking the count of the rows instead of the columns (or the rows cells)
Could you please confirm if this is a bug or try to explain how this works if it's not
thank you in advance
TPPDF Version used 2.3.0
Hi there, this looks like a copy-paste bug on my side.
I created a branch 233-fix-all-rows-alignment
for the WIP. Maybe you can take a closer look.
About changing it to a function: When I created this interface, I wanted a universal access using subscripts or close to subscripts = setters. Now, I think this would probably be smarter, as we could use more verbose names, rather than allRowsAlignment
.
I am open for recommendations, but unfortunately I am currently having busy times therefore I can't work on it too much, PR's are welcomed
I merged the progress for now, so the assertion errors don't occur anymore.
I guess we should improve the subscript methods maybe even replace them with methods at some point, at least for now I won't follow it, but feel free to create a PR/text how we could optimize them (in a new issue please).
Thanks