Using xcode 12.3
and swift 5.3
with the SwiftUI App
Life cycle to build a macOS
application, what is the best way to access and change the appearance and behaviour of the NSWindow
?
Edit: What I'm really after is the NSWindow
instance.
I've added an AppDelegate
, but as I understand it the NSWindow
is likely to be nil
, so unavailable for modification, and simply creating one here similar to the AppKit App Delegate
Life cycle method results in two windows appearing at launch.
One solution would be preventing the default window from appearing, and leaving it all to the applicationDidFinishLaunching
method, but not sure this is possible or sensible.
The WindowStyle
protocol looks to be a possible solution, but not sure how best to leverage that with a CustomWindowStyle
at this stage, and whether that provides access to the NSWindow
instance for fine-grained control.
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {
// In AppKit simply create the NSWindow and modify style.
// In SwiftUI creating an NSWindow and styling results in 2 windows,
// one styled and the other default.
}
}
@main
struct testApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate : AppDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}