Post

Replies

Boosts

Views

Activity

Reply to Does the new SwiftUI App Lifecycle support new windows on macOS/iPadOS?
A temporary workaround is to still rely on the AppKit Lifecycle and to manage multiple NSWindow instances manually. You can use NSHostingControllers to load SwiftUI views into the window. For example: import Cocoa import SwiftUI @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { var primaryWindow: NSWindow? func applicationDidFinishLaunching(_ aNotification: Notification) { let hostingController = NSHostingController(rootView: SwiftUIView()) window = NSWindow(contentViewController: hostingController) window?.toolbar = NSToolbar() window?.title = "SwiftUI Test Window" window?.makeKeyAndOrderFront(nil) } } struct SwiftUIView: View { var body: some View { Text("Hello, World!") .frame(minWidth: 640, maxWidth: .infinity, minHeight: 480, maxWidth: .infinity) } } Just make sure the Swift UI view has some kind of declared or implicit minimum size or the window will be extremely small/practically invisible. More windows can be opened the same way, which is what I was trying to achieve. I'd still like to figure out some kind of window management solution for SwiftUI projects. If anyone knows how to instantiate new windows directly through the SwiftUI lifecycle I'd love to know!
Jun ’20