Answer the question
In order to leave comments, you need to log in
How to display a dictionary in a table?
I have this dictionary:
var sites = defaults.dictionary(forKey: "Sites") as? [String: String] ?? [String: String]()
func tableView(tableView: NSTableView!, objectValueForTableColumn tableColumn: NSTableColumn!, row: Int) -> NSView? {
if let cell = tableView.makeView(withIdentifier: tableColumn!.identifier, owner: nil) as? NSTableCellView
{
let domain = [String](sites.keys)
let status = [String](sites.values)
if tableColumn?.title == "Sites" {
cell.text = domain[IndexPath.row]
} else {
cell.text = status[IndexPath.row]
}
return cell;
}
return mutableArrayValue[row]
}
Answer the question
In order to leave comments, you need to log in
Resolved: Dictionary is split into arrays and added to the table with arrays
func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {
var domain = [String](sites.keys)
var status = [String](sites.values)
if tableColumn?.title == "Sites" {
return domain[row]
}
else{
return status[row]
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question