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.

Ram Patra Published on August 6, 2020
Image placeholder

Keep reading

If this article was helpful, others might be too

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:

question macOS swift March 14, 2021 How to ignore mouse events in a view or window in macOS?

You can ignore mouse events in a window/view by adding just a single line of code.

question swiftui macOS January 26, 2024 How to hide the title bar in a SwiftUI macOS app?

Let’s say you have a view named ContentView and your main App file looks like this: