I have a dict of [String: NSNumber]
in my Card
class called data
(original!). There is an array of these [Card]
s in my document called deck
. I have deck
bound to an NSTableView
, which is displaying everything wonderfully.
Now I'm trying to write the setObjectValue
delegate method:
func tableView(tableView: NSTableView, setObjectValue anObject: AnyObject?, forTableColumn tableColumn: NSTableColumn?, row rowIndex: Int) {
print("set got called on row " + String(rowIndex) + " and column " + tableColumn!.identifier + " with " + String(anObject))
guard var d = deck?.geometryCards[rowIndex].data else { return }
guard let i = tableColumn?.identifier where i.length > 0 else { return }
let key = i.substring(0, length:(i.length - "Column".length))
d[key] = anObject
}
That doesn't work because the value in the dict is an NSNumber
, but the value coming back from the table is an AnyObject
. Now normally in Swift when I run into casting issues, this would work every time:
d[key] = NSNumber(anObject)
But that doesn't work here, because you need to specify the type, and in this case I don't know what it is - it could be Int or Double. What's the trick here?