How to set the width of an NSTableColumn in Swift

628 Views Asked by At

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.

1

There are 1 best solutions below

0
Marc Fearby On

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".