Basic indications to start to work with Tables in Euler #17
Unanswered
JavierVelascoPosada
asked this question in
Q&A
Replies: 1 comment
-
Hello Javier, class SimpleTableDataSource: TablesDataSource {
// 2D array to store cell values
private var grid: [[CellValue]]
init(rows: Int = 100, columns: Int = 26) {
// Initialize grid with empty values
self.grid = Array(repeating: Array(repeating: .empty, count: columns), count: rows)
}
func valueOfCell(x: Int, y: Int) -> CellValue {
// Check if coordinates are within bounds
guard y < grid.count && x < grid[0].count && x >= 0 && y >= 0 else {
return .nil
}
return grid[y][x]
}
func updateCell(content: CellValue, x: Int, y: Int) {
// Check if coordinates are within bounds
guard y < grid.count && x < grid[0].count && x >= 0 && y >= 0 else {
return
}
grid[y][x] = content
}
}
// Example usage:
let dataSource = SimpleTableDataSource()
dataSource.updateCell(content: CellValue(string: "3.456"), x: 1, y: 3) // Updates cell B4
let value = dataSource.valueOfCell(x: 1, y: 3) // Gets value of cell B4 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
@arguiot I appreciate if you can help me with this issue.
I am a beginner learning swift, I have only basic knowledge but I would like to start to use Euler.
I have written the following code to manage cells in a table with Euler
`var table = Tables()
public var dataSource: TablesDataSource?
table.dataSource?.updateCell(content: CellValue(string: "3.456"), x: 1, y: 1)
if let cell2 = table.dataSource?.valueOfCell(x: 1, y: 1) {
print(cell2)
} else {
print("error2")
}
`
The result is that nothing is allocated. Can you please help me with this issue?
Your help can help me to progress with Euler.
I am programing command line tools in Ubuntu.
Thank you very much for your help
Beta Was this translation helpful? Give feedback.
All reactions