lately I had to deal with window layering and ordering is Swift. I had to make sure some windows are always on top of other windows. This can be done with window levels.
in objective-c I found that you can simply call [NSWindow setLevel] with defined values such as NSMainMenuWindowLevel. in Swift, these defines doesnt exist. we have to use CGWindowLevelKey enum
However, this enum is not a value we can use directly for NSWindow.level. We have to convert it to a usable value by using CGWindowLevelForKey(), which returned an Int32. Since NSWindow.level is an Int, we also have to cast it to Int.
window.level = Int(CGWindowLevelForKey(.normalWindow))
Here's the list of the values of CGWindowLevelKey sorted from bottom to top. At the time of this writing, these values are generated with Swift 3.0.1 and macOS 10.12 SDK
baseWindow: -2147483648
minimumWindow: -2147483643
desktopWindow: -2147483623
desktopIconWindow: -2147483603
backstopMenu: -20
normalWindow: 0
floatingWindow: 3
tornOffMenuWindow: 3
modalPanelWindow: 8
utilityWindow: 19
dockWindow: 20
mainMenuWindow: 24
statusWindow: 25
popUpMenuWindow: 101
overlayWindow: 102
helpWindow: 200
draggingWindow: 500
numberOfWindowLevelKeys: 999
screenSaverWindow: 1000
assistiveTechHighWindow: 1500
cursorWindow: 2147483630
maximumWindow: 2147483631
in objective-c I found that you can simply call [NSWindow setLevel] with defined values such as NSMainMenuWindowLevel. in Swift, these defines doesnt exist. we have to use CGWindowLevelKey enum
However, this enum is not a value we can use directly for NSWindow.level. We have to convert it to a usable value by using CGWindowLevelForKey(), which returned an Int32. Since NSWindow.level is an Int, we also have to cast it to Int.
window.level = Int(CGWindowLevelForKey(.normalWindow))
Here's the list of the values of CGWindowLevelKey sorted from bottom to top. At the time of this writing, these values are generated with Swift 3.0.1 and macOS 10.12 SDK
baseWindow: -2147483648
minimumWindow: -2147483643
desktopWindow: -2147483623
desktopIconWindow: -2147483603
backstopMenu: -20
normalWindow: 0
floatingWindow: 3
tornOffMenuWindow: 3
modalPanelWindow: 8
utilityWindow: 19
dockWindow: 20
mainMenuWindow: 24
statusWindow: 25
popUpMenuWindow: 101
overlayWindow: 102
helpWindow: 200
draggingWindow: 500
numberOfWindowLevelKeys: 999
screenSaverWindow: 1000
assistiveTechHighWindow: 1500
cursorWindow: 2147483630
maximumWindow: 2147483631