The documentation makes it look as if it would be as easy as this:
var tc = NSTableColumn(identifier: "mycolumn")
tc.headerCell.stStringValue("foo")
The last line of code is a compile error, which I don't understand. On top of that I get a couple of different compile error message for this exact same line of code depending on what mood XCode seems to be in. I've seen the following compile errors:
I get this when try setting a variable and putting that in there:
I get this when I try the "foo \(bar)"
variant:
Hilariously enough if I declare a variable with type String?!
it says it Cannot convert the expression's type 'String?!' to type 'String?!'
I don't understand what is going on. Is this a bug?
If I try this in a playground, the playground actually wants to autocomplete with an extra argument, this format:
tc.headerCell.setStringValue("foo", resolvingEntities: false)
This has no compile time errors, but results in a seg fault at run time. This format is also not in the documentation.
I really have no idea what's going on and the error messages aren't helping.
I finally got this to work, despite the terrible error messages. The problem is that headerCell
is typed as AnyObject
, I had to cast it. The second problem was that in swift land it's a property, not a method.
This finally worked:
var tc = NSTableColumn(identifier: "mycolumn")
let hc = column1.headerCell as NSTableHeaderCell
hc.stringValue = "foo"