Swift : Window Size

any idea why this doesn’t work? (when all examples say it should)?

import Cocoa

class ViewController: NSViewController {
    private var window : NSWindow?

    override func viewDidAppear() {
        super.viewDidAppear()
        window         =  self.view.window
        window!.title  = "new title"
        window!.setFrame(CGRect(x:0,y:0,width:500,height:500), display: true)
        print(window!.frame)
    }
}

it says the size is 500x500, but that is NOT what is displayed

seems the window is (340,84,480,298) not (0,0,500,500)

AH HA!

I needed to set the MINSIZE first

window!.minSize = CGSize(width:1000,height:1000)
2 Likes

May I ask why you don’t check to make sure the Window exists? Or use the method viewWillMoveToWindow

Even then, I’d still recommend checking to make sure that the window exists, I know that viewWillMoveToWindow can be called while view.window == nil.