You can put a window on the screen by creating an NSWindow object and telling it to show itself.
import Cocoa
let rect = NSRect(x:100,y:100,width:100,height:100)
let window = NSWindow(contentRect: rect, styleMask: NSTitledWindowMask, backing: .Buffered, `defer`: false)
window.makeKeyAndOrderFront(nil)
makeKeyAndOrderFront tells the window to show itself and make it the frontmost window. The "frontmost window" in this case is from what I understand relative to the application, but the command line Swift interpreter doesn't have an application, you would have to create that as well. For now, I just set the window level to 1 to make it appear:
window.level = 1
This makes it float above all windows at level 0, i.e. the normal window level.
To make something actually appear in the window, you have to make an NSView and make it draw something:
class MyView : NSView {
override func drawRect(dirtyRect: NSRect) {
NSColor.redColor().set()
NSRectFill(dirtyRect)
}
}
window.contentView = MyView()
The problem here is that you still won't see anything. I'm guessing that the reason is that the runloop is not running. Unfortunately, I don't know how to start it correctly.