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:

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.

Ram Patra Published on August 6, 2020
Image placeholder

Keep reading

If this article was helpful, others might be too

question presentify macOS August 6, 2020 How to annotate or draw in JioMeet?

Reliance Jio has done a commendable job releasing a video conferencing app in a short time frame, however, it received criticisms that it copied pixel by pixel from Zoom. I actually agree with some of the criticisms but that’s for another blog post.

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 14, 2020 How to quit or close an app in macOS using Swift?

You can quit or exit an app with:NSApp.terminate(self)