In my MacOS SwiftUI App I want to display some views in new Windows. The calls shall be possible from several parts of the code so I decided, do implement it as a static func of as special struct like this.
Works fine - there is something to be said against it?
struct Appwindows {
static func newWindow(forSpecialView view: SpecialView, title: String = "new Window")
{ let newWindow = newWindowInternal(title: title)!
newWindow.contentView = NSHostingView(rootView: view)
}
private static func newWindowInternal(title: String = "new Window") -> NSWindow!
{ var newWindow: NSWindow!
newWindow = NSWindow(
contentRect: NSRect(x: 20, y: 20, width: 680, height: 600),
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
backing: .buffered,
defer: false)
newWindow.center()
newWindow.isReleasedWhenClosed = false
newWindow.title = title
newWindow.makeKeyAndOrderFront(nil)
return newWindow
}
}
Is there a way to make it more generic, so that any kind of views could be passed to the func?