Setting Window Level Swift Error OSX

When trying to set the window level in swift im, getting the Use of unresolved identifier 'window' error using:

window.level = Int(CGWindowLevelForKey(Int32(kCGScreenSaverWindowLevelKey)))

or

window.level = NSScreenSaverWindowLevel

Ive checked here How to set window level in Swift

Here is Mac OS X, make a window go through the menu bar

Here is the NSWindow Class

I don't seem to see the NSViewController or NSWindowController properties of a window

+6
source share
3 answers

Subclass NSWindowController

in windowDidLoad()

window?.level = Int(CGWindowLevelForKey(Int32(kCGScreenSaverWindowLevelKey)))

+4
source

Update for Swift 2:

 panel.level = Int(CGWindowLevelForKey(CGWindowLevelKey.PopUpMenuWindowLevelKey)) 
+10
source

Update for Swift 3:

 window.level = Int(CGWindowLevelForKey(CGWindowLevelKey.popUpMenuWindow)) 
+3
source

Source: https://habr.com/ru/post/980363/


All Articles