You need to use NSWindow.Level
to stay above other apps.
Set Window Level:
It controls your apps z-axis. Higher the value goes higher level.
There are predefined values like normal, floating and all.
view.window?.level = NSWindow.Level.floating
But you can define your own to achieve much higher level like this
view.window?.level = NSWindow.Level(rawValue: 104) //where 104 is the window level
For more information about NSWindow.Level
check here
Set Collection Behaviour:
It is what let your app stays in other apps space. Refer the documentation for detailed explanation check here
view.window?.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary]
My above solution will only if you are using NSPanel
which is a subclass of NSWindow
.
Set Activation Policy:
If you prefer to use NSWindow
, you need to additionally set the NSApplication.ActivationPolicy
to .accessory
like this
NSApplication.shared.setActivationPolicy(NSApplication.ActivationPolicy.accessory)
Activation Policy determines how your app can be activated.
For more information check here