Loading...

How to open an app's window on top of all others in Swift?

question macOS swift
Ram Patra Published on August 6, 2020
SDK - macOS 10.0+

You can open your app’s window on top of all other open application windows with the below code:

windowController?.showWindow(self)
NSApp.activate(ignoringOtherApps: true)

For example, in my app––Presentify––when you click on ‘Preferences’, the Settings window opens up on top of all other applications. With just windowController?.showWindow(self), the window would open fine, but it won’t be visible to the user if other apps are open.

Presentify

Take your presentation to the next level.

FaceScreen

Put your face and name on your screen.

ToDoBar

Your to-dos on your menu bar.

Ram Patra Published on August 6, 2020
Image placeholder

Keep reading

If this article was helpful, others might be too

June 7, 2020 How to add Global Key Shortcuts to your macOS app using MASShortcut

Adding Global Keyboard Shortcuts to your macOS app can be a pain as there isn’t a Cocoa API for the same. You would have to rely on the old, most of which are deprecated, Carbon API.

question macOS swift August 6, 2020 How to keep an app's window always on top of others in Swift?

Before launching the window, just use the appropriate window level, and you’re done.

question macOS swift August 14, 2020 How to detect Delete key press in Swift?

Delete key press detection is slightly different than other keys. It uses NSDeleteCharacter like below: