How to create a window outside the screen

I am studying MAC OS development and I used Swift and Cocoa to create a window that I want to display outside the screen. My code looks like this:

    @IBAction func tapShowSplitWindow(_ sender: Any) {
        let initRect = NSRect(x: -100, y: -100, width: 300.0, height: 300.0)

        var window = NSWindow(contentRect: initRect,styleMask: .titled, backing: .buffered, defer: false)
        window.contentView = NSView()
        window.contentView?.wantsLayer = true
        window.contentView?.layer?.backgroundColor = NSColor.red.cgColor
        
        window.makeKeyAndOrderFront(self)
    }

The window will appear in the bottom left corner of the screen, and I expect it to be outside the screen. so why? and how to show it outside

        let initRect = NSRect(x: -100, y: -100, width: 300.0, height: 300.0)

With this rect, you should see a part of the window frame (the 2/3 top right):

  • 100 ... 300 on x (0 to 100 of frame is offscreen)
  • 100 ... 300 on y (0 to 100 of frame is offscreen)

How do you expect it to be completely offScreen ?

Just use:

        let initRect = NSRect(x: -400, y: -400, width: 300.0, height: 300.0)

to get it offscreen.

oh. I use your code. It's useless. I don't think you've tried

How to create a window outside the screen
 
 
Q