How to create multidimentional arrays and get/set values at a specific row/column?

Ignoring SwiftUI aspects of this question (which are prohibited here) this is the way to work with a multidimensional array:

listArray.insert([UUID().uuidString, "John", "Jane"], at: 0)
or just
listArray.append([UUID().uuidString, "John", "Jane"]) // appends to end

label = listArray[1][2] // get's second element of first row

listArray.remove(at: 0) // removes 0's element
listArray.remove(at: 0) // removes the other element (which is now 0's)
listArray.removeAll() // or just remove all

But perhaps you don't even need a multidimensional array, but an array of structs instead:

struct Row {
    let id: UUID
    let name: String
    let lastName: String
}
var rows: [Row] = [:]

rows.append(Row(id: UUID(), name: "John", lastName: "Smith")]
let lastName = rows[1].lastName
rows.removeAll()

Other thing: name variables starting with lower case (upper cased names are for types).

2 Likes