Change macOS window level with SwiftUI (to make a floating window)

Viewed 473

Hi is there a way to change the window level with SwiftUI so I can make a floating window for my mac app? I am using the SwiftUI life cycle

1 Answers

You can access your windows with NSApplication.shared.windows and set the level for each one.

For instance:

Button("Float windows") {
    for window in NSApplication.shared.windows {
        window.level = .floating
    }
}
Related