1

I'd like to programmatically set the width of some NSTableColumns in code (so that I can restore the widths on startup), but I don't really know how to apply what's written in the docs

for column in table.tableColumns {
    var w: CGFloat = 125
    column.setWidth(w) 
    println("\(column.identifier!)") // this prints my identifiers, so I know these are my columns and not something else I'm not interested in
}

The error I get is as follows: '(@lvalue CGFloat) -> $T3' is not identical to 'CGFloat'

With just 125 as the argument to setWidth the error says '(IntegerLiteralConvertable) -> etc...'

Code completion in XCode shows four versions of setWidth() each of which take at least two arguments, and none with just the width which is all I care about. My guess is that the docs don't match XCode 6.1.1, perhaps? It suggests there's just a setWidth() method, but in real life I have to choose between four equally confusing versions.

Shamas S
  • 7,507
  • 10
  • 46
  • 58
Marc Fearby
  • 1,305
  • 1
  • 13
  • 28
  • You should be able to just treat `width` as a property: `column.width = w` or `column.width = 125`. Does that work? – Ken Thomases Apr 04 '15 at 09:13
  • I didn't try that, but it doesn't like it: "Cannot assign to 'width' in 'column'" – Marc Fearby Apr 04 '15 at 12:06
  • Calling "column.setWidth(125, ofColumn: 0)" results in this error: "-[NSTableColumn setWidth:ofColumn:]: unrecognized selector sent to instance 0x600000082b70". Same deal with setWidth:forSegment: – Marc Fearby Apr 05 '15 at 06:10

1 Answers1

0

One Quincey_Morris gave me this answer in the Apple developer forums (I hope this isn't a breach of Apple's terms and conditions). I had to cast column "as [NSTableColumn]" before the opening brace of my for loop before I could just call "column.width = 125".

Marc Fearby
  • 1,305
  • 1
  • 13
  • 28