I must be missing something simple. I want to make a 2D array where each "column" has two "rows", a name string and a dictionary. So here's an example with four strings. I want to attach a dictionary to each string. A few things I've tried (in Playgorund) are shown.
var myNames = ["Home", "Accesory", "Service", "Characterstic"] // My array of name strings
var myDict: [String: Any] = [ // The dictionary I want to attach to each string name
"addtionalRows" : 1,
"cellIdentifier" : "idCellNormal",
"isExpandable" : true,
"isExpanded" : false,
"isVisible" : true,
"primaryTitle" : "",
"secondaryTitle" : "Fullname",
"value" : ""
]
var test2DArray = [[String](), [String: Any]()] // This throws an error
var test2DArray = [[String](), [String: Any]()] as [Any] // This does not cause an error, but doesn't seem to work
test2DArray = [myNames, myDict] // Likewise, this does not cause an error but it doesn't fill in the array
for row in HomekitRows {
test.append(HomekitRows[row], cellProps) // This fails if the "as [Any]" form above is used
}
What am I missing?
[UPDATE] Rather than mixing types, I decided I could use an array of just dictionaries. I added the key "category" to the myDict declared above and put my name string into it. It works!
var myDictArray: [[String: Any]] = [[:]]
for row in myNames {
myDict.updateValue(row, forKey: "category") // This puts my strings directly into each dictionary
if row == "Service" {
myDict.updateValue(false, forKey: "isVisible") // This is just a test to verify I can alter dictionary values
}
myDictArray.append(myDict) // This works!!
}